async_openai/types/audio/
sdk.rs

1use crate::{error::OpenAIError, types::audio::CreateSpeechResponse, util::create_all_dir};
2use std::path::Path;
3
4impl CreateSpeechResponse {
5    pub async fn save<P: AsRef<Path>>(&self, file_path: P) -> Result<(), OpenAIError> {
6        let dir = file_path.as_ref().parent();
7
8        if let Some(dir) = dir {
9            create_all_dir(dir)?;
10        }
11
12        tokio::fs::write(file_path, &self.bytes)
13            .await
14            .map_err(|e| OpenAIError::FileSaveError(e.to_string()))?;
15
16        Ok(())
17    }
18}