pub struct Audio {
pub model: Model,
pub prompt: Option<String>,
pub response_format: Option<Format>,
pub temperature: Option<f32>,
pub language: Option<Language>,
}
Expand description
Given a prompt and an instruction, the model will return an edited version of the prompt.
Fields§
§model: Model
ID of the model to use. Only whisper-1
is currently available.
prompt: Option<String>
An optional text to guide the model’s style or continue a previous audio segment. The prompt should match the audio language.
response_format: Option<Format>
The format of the transcript output, in one of these options: json
,
text
, srt
, verbose_json
, or vtt
.
temperature: Option<f32>
The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.
language: Option<Language>
The language of the input audio. Supplying the input language in ISO-639-1 format will improve accuracy and latency.
Implementations§
source§impl Audio
impl Audio
sourcepub fn set_prompt(&mut self, content: &str)
pub fn set_prompt(&mut self, content: &str)
sourcepub async fn transcription(
&self,
file_name: String,
bytes: Vec<u8>
) -> Result<AudioResponse, Box<dyn Error>>
pub async fn transcription( &self, file_name: String, bytes: Vec<u8> ) -> Result<AudioResponse, Box<dyn Error>>
Send transcription request to OpenAI.
The audio file to transcribe, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm.
Arguments
file_name
- Audio file namebytes
- Bytes vector of the file
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17
async fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
log4rs::init_file("log4rs.yml", Default::default()).unwrap();
let audio = Audio::default();
let file_path = PathBuf::from("D:\\Contents\\Downloads\\20220918_000937.m4a");
let result = audio
.transcription(String::from("20220918_000937.m4a"), std::fs::read(file_path).unwrap())
.await?;
println!("{:?}", result.text);
Ok(())
}
sourcepub async fn translation(
&self,
file_name: String,
bytes: Vec<u8>
) -> Result<AudioResponse, Box<dyn Error>>
pub async fn translation( &self, file_name: String, bytes: Vec<u8> ) -> Result<AudioResponse, Box<dyn Error>>
Translates audio into into English.
The audio file to transcribe, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm.
Arguments
file_name
- Audio file namebytes
- Bytes vector of the file
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17
async fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
log4rs::init_file("log4rs.yml", Default::default()).unwrap();
let audio = Audio::default();
let file_path = PathBuf::from("D:\\Contents\\Downloads\\20220918_000937.m4a");
let result = audio
.translation(String::from("20220918_000937.m4a"), std::fs::read(file_path).unwrap())
.await?;
println!("{:?}", result.text);
Ok(())
}