I am trying Speech to text with Azure Speech Recognizer service but when ı run this code, ı get error
code is;
import azure.cognitiveservices.speech as speechsdk
subscription_key = "key is here"
service_region = "region is here too"
audio_file = "data file path"
speech_config = speechsdk.SpeechConfig(subscription=subscription_key, region=service_region)
audio_input = speechsdk.AudioConfig(filename=audio_file)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_input,language="tr")
result = speech_recognizer.recognize_once()
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
print("Metin: {}".format(result.text))
elif result.reason == speechsdk.ResultReason.NoMatch:
print("Eşleşme bulunamadı: {}".format(result.no_match_details.reason))
elif result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = result.cancellation_details
print("Tanıma iptal edildi: {}".format(cancellation_details.reason))
if cancellation_details.reason == speechsdk.CancellationReason.Error:
print("Hata ayrıntıları: {}".format(cancellation_details.reason_details))
and error is;
---> 16 speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_input,language="tr")
RuntimeError: Exception with error code:
[CALL STACK BEGIN]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1aa875) [0x7fd4c79aa875]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1aaf64) [0x7fd4c79aaf64]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1ac537) [0x7fd4c79ac537]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1acbee) [0x7fd4c79acbee]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1919bc) [0x7fd4c79919bc]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x194b3e) [0x7fd4c7994b3e]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1346c5) [0x7fd4c79346c5]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x19b253) [0x7fd4c799b253]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x19b6c2) [0x7fd4c799b6c2]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x13e447) [0x7fd4c793e447]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1e65f6) [0x7fd4c79e65f6]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x139b9b) [0x7fd4c7939b9b]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x20dfe2) [0x7fd4c7a0dfe2]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(recognizer_create_speech_recognizer_from_source_lang_config+0x116) [0x7fd4c78bf641]
/lib/x86_64-linux-gnu/libffi.so.8(+0x7e2e) [0x7fd509008e2e]
/lib/x86_64-linux-gnu/libffi.so.8(+0x4493) [0x7fd509005493]
/usr/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so(+0xa3e9) [0x7fd50902e3e9]
[CALL STACK END]
Exception with an error code: 0xa (SPXERR_INVALID_HEADER)
ı have azure portal account and ı got relative information from Azure Speech service
Based on the provided information, the error message suggests that there might be an issue with the configuration of the
SpeechRecognizer
object.One possible issue might be the language code you are using in your code. To fix this, you can use tr-TR in place of tr as your language code.
With above change the code successfully executed.
Please refer to this documentation to get details regarding other supported languages and codes.