@@ -157,17 +157,17 @@ def translate_speech_to_text():
157
157
translation_config = translation_config)
158
158
159
159
print (' Say something...' )
160
- result = translation_recognizer.recognize_once()
161
- print (get_result_text(reason = result .reason, result = result ))
160
+ translation_recognition_result = translation_recognizer.recognize_once()
161
+ print (get_result_text(reason = translation_recognition_result .reason, result = translation_recognition_result ))
162
162
163
- def get_result_text (reason , result ):
163
+ def get_result_text (reason , translation_recognition_result ):
164
164
reason_format = {
165
165
speechsdk.ResultReason.TranslatedSpeech:
166
- f ' RECOGNIZED " { from_language} ": { result .text} \n ' +
167
- f ' TRANSLATED into " { to_language} "": { result .translations[to_language]} ' ,
168
- speechsdk.ResultReason.RecognizedSpeech: f ' Recognized: " { result .text} " ' ,
169
- speechsdk.ResultReason.NoMatch: f ' No speech could be recognized: { result .no_match_details} ' ,
170
- speechsdk.ResultReason.Canceled: f ' Speech Recognition canceled: { result .cancellation_details} '
166
+ f ' RECOGNIZED " { from_language} ": { translation_recognition_result .text} \n ' +
167
+ f ' TRANSLATED into " { to_language} "": { translation_recognition_result .translations[to_language]} ' ,
168
+ speechsdk.ResultReason.RecognizedSpeech: f ' Recognized: " { translation_recognition_result .text} " ' ,
169
+ speechsdk.ResultReason.NoMatch: f ' No speech could be recognized: { translation_recognition_result .no_match_details} ' ,
170
+ speechsdk.ResultReason.Canceled: f ' Speech Recognition canceled: { translation_recognition_result .cancellation_details} '
171
171
}
172
172
return reason_format.get(reason, ' Unable to recognize speech' )
173
173
@@ -222,17 +222,17 @@ def translate_speech_to_text():
222
222
223
223
print (f ' Say something in " { from_language} " and we \' ll translate into " { to_language} ". ' )
224
224
225
- result = translation_recognizer.recognize_once()
226
- print (get_result_text(reason = result .reason, result = result ))
225
+ translation_recognition_result = translation_recognizer.recognize_once()
226
+ print (get_result_text(reason = translation_recognition_result .reason, result = translation_recognition_result ))
227
227
228
- def get_result_text (reason , result ):
228
+ def get_result_text (reason , translation_recognition_result ):
229
229
reason_format = {
230
230
speechsdk.ResultReason.TranslatedSpeech:
231
- f ' Recognized " { from_language} ": { result .text} \n ' +
232
- f ' Translated into " { to_language} "": { result .translations[to_language]} ' ,
233
- speechsdk.ResultReason.RecognizedSpeech: f ' Recognized: " { result .text} " ' ,
234
- speechsdk.ResultReason.NoMatch: f ' No speech could be recognized: { result .no_match_details} ' ,
235
- speechsdk.ResultReason.Canceled: f ' Speech Recognition canceled: { result .cancellation_details} '
231
+ f ' Recognized " { from_language} ": { translation_recognition_result .text} \n ' +
232
+ f ' Translated into " { to_language} "": { translation_recognition_result .translations[to_language]} ' ,
233
+ speechsdk.ResultReason.RecognizedSpeech: f ' Recognized: " { translation_recognition_result .text} " ' ,
234
+ speechsdk.ResultReason.NoMatch: f ' No speech could be recognized: { translation_recognition_result .no_match_details} ' ,
235
+ speechsdk.ResultReason.Canceled: f ' Speech Recognition canceled: { translation_recognition_result .cancellation_details} '
236
236
}
237
237
return reason_format.get(reason, ' Unable to recognize speech' )
238
238
@@ -264,21 +264,21 @@ def translate_speech_to_text():
264
264
translation_config = translation_config)
265
265
266
266
print (' Say something...' )
267
- result = translation_recognizer.recognize_once()
268
- synthesize_translations(result = result )
267
+ translation_recognition_result = translation_recognizer.recognize_once()
268
+ synthesize_translations(result = translation_recognition_result )
269
269
270
- def synthesize_translations (result ):
270
+ def synthesize_translations (translation_recognition_result ):
271
271
language_to_voice_map = {
272
272
" de" : " de-DE-KatjaNeural" ,
273
273
" en" : " en-US-AriaNeural" ,
274
274
" it" : " it-IT-ElsaNeural" ,
275
275
" pt" : " pt-BR-FranciscaNeural" ,
276
276
" zh-Hans" : " zh-CN-XiaoxiaoNeural"
277
277
}
278
- print (f ' Recognized: " { result .text} " ' )
278
+ print (f ' Recognized: " { translation_recognition_result .text} " ' )
279
279
280
- for language in result .translations:
281
- translation = result .translations[language]
280
+ for language in translation_recognition_result .translations:
281
+ translation = translation_recognition_result .translations[language]
282
282
print (f ' Translated into " { language} ": { translation} ' )
283
283
284
284
speech_config = speechsdk.SpeechConfig(subscription = speech_key, region = service_region)
0 commit comments