1use std::path::Path;
2use std::process::Command as ProcessCommand;
3use tempfile::NamedTempFile;
4
5pub fn play_audio_and_cleanup(file_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
6 let status = ProcessCommand::new("mpv")
7 .arg("--no-video")
8 .arg("--really-quiet")
9 .arg(file_path)
10 .status()?;
11
12 if !status.success() {
13 return Err("mpv failed to play audio".into());
14 }
15
16 std::fs::remove_file(file_path)?;
17 Ok(())
18}
19
20pub fn create_temp_audio_file() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
21 let temp_file = NamedTempFile::new()?;
22 let temp_path = temp_file.path().with_extension("wav");
23 temp_file.persist(&temp_path)?;
24 Ok(temp_path)
25}