feat: handles submitted audio

This commit is contained in:
Per Stark
2025-07-29 18:39:26 +02:00
parent b8272d519d
commit 33300d3193
10 changed files with 69 additions and 6 deletions
@@ -0,0 +1,32 @@
use async_openai::types::{CreateTranscriptionRequestArgs, AudioResponseFormat};
use common::{
error::AppError,
storage::{
db::SurrealDbClient,
types::system_settings::SystemSettings,
},
};
/// Transcribes an audio file using the configured OpenAI Whisper model.
pub async fn transcribe_audio_file(
file_path: &str,
db_client: &SurrealDbClient,
openai_client: &async_openai::Client<async_openai::config::OpenAIConfig>,
) -> Result<String, AppError> {
let system_settings = SystemSettings::get_current(db_client).await?;
let model = system_settings.voice_processing_model;
let request = CreateTranscriptionRequestArgs::default()
.file(file_path)
.model(model)
.response_format(AudioResponseFormat::Json)
.build()?;
let response = openai_client
.audio()
.transcribe(request)
.await
.map_err(|e| AppError::Processing(format!("Audio transcription failed: {}", e)))?;
Ok(response.text)
}
+1
View File
@@ -1,5 +1,6 @@
pub mod image_parsing;
pub mod llm_instructions;
pub mod audio_transcription;
use common::error::AppError;
use std::collections::HashMap;