@@ -29,6 +29,8 @@ struct Args {
2929 model : Option < String > ,
3030 #[ arg( long) ]
3131 region : Option < String > ,
32+ #[ arg( long) ]
33+ diarization : bool ,
3234}
3335
3436#[ derive( Debug , Clone , Copy , ValueEnum ) ]
@@ -52,10 +54,15 @@ async fn main() -> Result<()> {
5254 let languages = Languages :: new ( args. language ) ?;
5355 let model = args. model . as_deref ( ) ;
5456 let region = args. region . as_deref ( ) ;
57+ let diarization = args. diarization ;
5558
5659 match args. input . as_deref ( ) {
57- Some ( path) => recognize_from_wav ( args. provider , path, & languages, model, region) . await ?,
58- None => recognize_from_microphone ( args. provider , & languages, model, region) . await ?,
60+ Some ( path) => {
61+ recognize_from_wav ( args. provider , path, & languages, model, region, diarization) . await ?
62+ }
63+ None => {
64+ recognize_from_microphone ( args. provider , & languages, model, region, diarization) . await ?
65+ }
5966 }
6067
6168 Ok ( ( ) )
@@ -67,6 +74,7 @@ async fn recognize_from_wav(
6774 languages : & Languages ,
6875 model : Option < & str > ,
6976 region : Option < & str > ,
77+ diarization : bool ,
7078) -> Result < ( ) > {
7179 let format = AudioFormat {
7280 channels : 1 ,
@@ -83,14 +91,24 @@ async fn recognize_from_wav(
8391 producer. produce ( frame) ?;
8492 }
8593
86- recognize ( provider, format, input_consumer, languages, model, region) . await
94+ recognize (
95+ provider,
96+ format,
97+ input_consumer,
98+ languages,
99+ model,
100+ region,
101+ diarization,
102+ )
103+ . await
87104}
88105
89106async fn recognize_from_microphone (
90107 provider : Provider ,
91108 languages : & Languages ,
92109 model : Option < & str > ,
93110 region : Option < & str > ,
111+ diarization : bool ,
94112) -> Result < ( ) > {
95113 // Keep an output sink alive so Bluetooth headsets can switch to a bidirectional profile.
96114 let _output_sink = match DeviceSinkBuilder :: open_default_sink ( ) {
@@ -131,7 +149,16 @@ async fn recognize_from_microphone(
131149
132150 stream. play ( ) . expect ( "Failed to play stream" ) ;
133151
134- recognize ( provider, format, input_consumer, languages, model, region) . await
152+ recognize (
153+ provider,
154+ format,
155+ input_consumer,
156+ languages,
157+ model,
158+ region,
159+ diarization,
160+ )
161+ . await
135162}
136163
137164async fn recognize (
@@ -141,6 +168,7 @@ async fn recognize(
141168 languages : & Languages ,
142169 model : Option < & str > ,
143170 region : Option < & str > ,
171+ diarization : bool ,
144172) -> Result < ( ) > {
145173 let ( output_producer, mut output_consumer) = unbounded_channel ( ) ;
146174 let ( conversation_input_producer, conversation_input_consumer) = channel ( 16_384 ) ;
@@ -150,6 +178,7 @@ async fn recognize(
150178 languages,
151179 model,
152180 region,
181+ diarization,
153182 Conversation :: new (
154183 InputModality :: Audio { format } ,
155184 [ OutputModality :: Text , OutputModality :: InterimText ] ,
@@ -190,6 +219,7 @@ async fn start_conversation(
190219 languages : & Languages ,
191220 model : Option < & str > ,
192221 region : Option < & str > ,
222+ diarization : bool ,
193223 conversation : Conversation ,
194224) -> Result < ( ) > {
195225 match provider {
@@ -203,11 +233,15 @@ async fn start_conversation(
203233 subscription_key : env:: var ( "AZURE_SUBSCRIPTION_KEY" )
204234 . expect ( "AZURE_SUBSCRIPTION_KEY undefined" ) ,
205235 language : languages. join_csv ( ) ,
236+ diarization,
206237 speech_gate : false ,
207238 } ;
208239 AzureTranscribe . conversation ( params, conversation) . await
209240 }
210241 Provider :: Elevenlabs => {
242+ if diarization {
243+ bail ! ( "--diarization is only supported for the azure provider" ) ;
244+ }
211245 if region. is_some ( ) {
212246 bail ! ( "--region is only supported for the google provider" ) ;
213247 }
@@ -234,6 +268,9 @@ async fn start_conversation(
234268 . await
235269 }
236270 Provider :: Google => {
271+ if diarization {
272+ bail ! ( "--diarization is only supported for the azure provider" ) ;
273+ }
237274 let region = region
238275 . map ( str:: to_owned)
239276 . or_else ( || env:: var ( "GOOGLE_TRANSCRIBE_REGION" ) . ok ( ) ) ;
@@ -259,6 +296,9 @@ async fn start_conversation(
259296 GoogleTranscribe . conversation ( params, conversation) . await
260297 }
261298 Provider :: Aristech => {
299+ if diarization {
300+ bail ! ( "--diarization is only supported for the azure provider" ) ;
301+ }
262302 if region. is_some ( ) {
263303 bail ! ( "--region is only supported for the google provider" ) ;
264304 }
0 commit comments