|
| 1 | +use std::sync::Arc; |
| 2 | + |
| 3 | +use hypr_listener2_core::{BatchEvent, BatchParams, BatchProvider, BatchRuntime}; |
| 4 | + |
| 5 | +pub struct Args { |
| 6 | + pub file: String, |
| 7 | + pub provider: BatchProvider, |
| 8 | + pub base_url: String, |
| 9 | + pub api_key: String, |
| 10 | + pub model: Option<String>, |
| 11 | + pub language: String, |
| 12 | + pub keywords: Vec<String>, |
| 13 | +} |
| 14 | + |
| 15 | +struct CliBatchRuntime; |
| 16 | + |
| 17 | +impl BatchRuntime for CliBatchRuntime { |
| 18 | + fn emit(&self, event: BatchEvent) { |
| 19 | + match &event { |
| 20 | + BatchEvent::BatchStarted { .. } => { |
| 21 | + eprintln!("Transcribing..."); |
| 22 | + } |
| 23 | + BatchEvent::BatchResponseStreamed { percentage, .. } => { |
| 24 | + eprintln!("Progress: {:.0}%", percentage * 100.0); |
| 25 | + } |
| 26 | + BatchEvent::BatchResponse { response, .. } => { |
| 27 | + for channel in &response.results.channels { |
| 28 | + for alt in &channel.alternatives { |
| 29 | + if !alt.transcript.is_empty() { |
| 30 | + println!("{}", alt.transcript); |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + BatchEvent::BatchFailed { error, .. } => { |
| 36 | + eprintln!("Error: {error}"); |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +pub async fn run(args: Args) { |
| 43 | + let languages = vec![ |
| 44 | + args.language |
| 45 | + .parse::<hypr_language::Language>() |
| 46 | + .expect("invalid language code"), |
| 47 | + ]; |
| 48 | + |
| 49 | + let session_id = uuid::Uuid::new_v4().to_string(); |
| 50 | + let runtime = Arc::new(CliBatchRuntime); |
| 51 | + |
| 52 | + let params = BatchParams { |
| 53 | + session_id, |
| 54 | + provider: args.provider, |
| 55 | + file_path: args.file, |
| 56 | + model: args.model, |
| 57 | + base_url: args.base_url, |
| 58 | + api_key: args.api_key, |
| 59 | + languages, |
| 60 | + keywords: args.keywords, |
| 61 | + }; |
| 62 | + |
| 63 | + if let Err(e) = hypr_listener2_core::run_batch(runtime, params).await { |
| 64 | + eprintln!("Batch transcription failed: {e}"); |
| 65 | + std::process::exit(1); |
| 66 | + } |
| 67 | +} |
0 commit comments