- https://learn.microsoft.com/en-us/ azure/ai-services/speech-service/get-started-speech-to-text?tabs=windows%2Cterminal&pivots=programming-language-python
Код: Выделить всё
import os
import azure.cognitiveservices.speech as speechsdk
# Explicitly set the values if not already set in the environment
os.environ["SPEECH_KEY"] = "838f0db5598343dcbd8b0d42587501c4"
os.environ["SPEECH_REGION"] = "southeastasia"
SPEECH_KEY = os.getenv("SPEECH_KEY")
SPEECH_REGION = os.getenv("SPEECH_REGION")
def recognize_from_microphone():
# This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
speech_config = speechsdk.SpeechConfig(subscription=SPEECH_KEY, region=SPEECH_REGION)
speech_config.speech_recognition_language="en-US"
print(SPEECH_KEY)
print(SPEECH_REGION)
audio_config =speechsdk.audio.AudioConfig(use_default_microphone=True)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
print("Speak into your microphone.")
speech_recognition_result = speech_recognizer.recognize_once_async().get()
if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:
print("Recognized: {}".format(speech_recognition_result.text))
elif speech_recognition_result.reason == speechsdk.ResultReason.NoMatch:
print("No speech could be recognized: {}".format(speech_recognition_result.no_match_details))
elif speech_recognition_result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = speech_recognition_result.cancellation_details
print("Speech Recognition canceled: {}".format(cancellation_details.reason))
if cancellation_details.reason == speechsdk.CancellationReason.Error:
print("Error details: {}".format(cancellation_details.error_details))
print("Did you set the speech resource key and region values?")
recognize_from_microphone()
Версия Python — Python 3.11.10
Когнитивная речь Azure версия - 1.41.1
Код: Выделить всё
RuntimeError: Exception with error code:
[CALL STACK BEGIN]
> CreateModuleObject
- CreateModuleObject
- audio_config_get_audio_processing_options
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- audio_config_get_audio_processing_options
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
[CALL STACK END]
Exception with an error code: 0xe (SPXERR_MIC_NOT_AVAILABLE)
Подробнее здесь: https://stackoverflow.com/questions/791 ... -available
Мобильная версия