Azure Text-to Speech Error Code

Sohaib Ashraf 0 Reputation points
2023-08-17T06:54:22.2733333+00:00

Hello I am working on an app that reads text using azure tts; my python script that uses Azure TTS runs fine. When I deploy the script using pyinstaller I get error:

SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND

similar issue was reported by [https://learn.microsoft.com/en-us/answers/questions/1184428/azure-text-to-speech-error-code-0x38-(spxerr-audio](https://learn.microsoft.com/en-us/answers/questions/1184428/azure-text-to-speech-error-code-0x38-(spxerr-audio)

but the solution provided does not solve my problem since i want to read the text in the speaker.

Complete Error Info:

PS E:\Sohaib\upwork\TranslateAndTTS\TranslateAndTTS\dist> .\translateandread.exe

Traceback (most recent call last):                                                                                       
File "translatepb.py", line 144, in <module>                                                                            
File "translatepb.py", line 90, in mainrun                                                                              
File "translatepb.py", line 60, in speakstr                                                                             
File "translatepb.py", line 121, in azureSpeak                                                                          
File "azure\cognitiveservices\speech\speech.py", line 2149, in __init__                                                 
File "azure\cognitiveservices\speech\interop.py", line 62, in _call_hr_fn                                               
File "azure\cognitiveservices\speech\interop.py", line 55, in _raise_if_failed                                          
File "azure\cognitiveservices\speech\interop.py", line 50, in __try_get_error                                         
RuntimeError: Exception with error code:                                                                                
[CALL STACK BEGIN]                                                                                                                                                                                                                                  
> pal_string_to_wstring                                                                                                 
- synthesizer_create_speech_synthesizer_from_config                                                                     
- synthesizer_create_speech_synthesizer_from_config                                                                     
- ffi_prep_go_closure                                                                                                   
- ffi_call_go                                                                                                           
- ffi_call                                                                                                              
- 00007FFFA7023CC5 (SymFromAddr() error: Attempt to access invalid address.)                                            
- 00007FFFA7022BEA (SymFromAddr() error: Attempt to access invalid address.)                                            
- 00007FFFA70227E8 (SymFromAddr() error: Attempt to access invalid address.)                                            
- PyList_AsTuple                                                                                                        
- PyEval_EvalFrameDefault                                                                                               
- PyFunction_Vectorcall                                                                                                 
- PyList_AsTuple                                                                                                        
- PyEval_EvalFrameDefault                                                                                               
- PyFunction_Vectorcall                                                                                                 
- PyObject_GetBuffer                                                                                                                                                                                                                        
[CALL STACK END]                                                                                                                                                                                                                                
Exception with an error code: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND)  

Python Code:

def azureSpeak(text):
    # Add your key and endpoint
    key = config.get('azureTTS', 'key')
    location = config.get('azureTTS', 'location')
    voiceid = config.get('azureTTS', 'voiceid')

    speech_config = speechsdk.SpeechConfig(subscription=key, region=location)
    audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)


    # The language of the voice that speaks.
    speech_config.speech_synthesis_voice_name = voiceid

    speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)

    speech_synthesis_result = speech_synthesizer.speak_text_async(text).get()
    
    if speech_synthesis_result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
        print("Speech synthesized for text [{}]".format(text))
    
        # save to .wav file
        timestr = time.strftime("%Y%m%d-%H%M%S")
        filename = os.path.join(wav_files_path, timestr+'.wav')
        stream = speechsdk.AudioDataStream(speech_synthesis_result)
        stream.save_to_wav_file(filename)

    elif speech_synthesis_result.reason == speechsdk.ResultReason.Canceled:
        cancellation_details = speech_synthesis_result.cancellation_details
        print("Speech synthesis canceled: {}".format(cancellation_details.reason))
        if cancellation_details.reason == speechsdk.CancellationReason.Error:
            if cancellation_details.error_details:
                print("Error details: {}".format(cancellation_details.error_details))
                print("Did you set the speech resource key and region values?")

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,600 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ramr-msft 17,826 Reputation points
    2023-08-17T09:27:29.46+00:00

    @Sohaib Ashraf Thanks for the question, SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND can be returned, for example, when multiple versions of Python have been installed, or if you're not using a supported version of Python. You can try using a different python interpreter or uninstall all python versions and re-install the latest version of python and the Speech SDK.

    and on the remote app service the default audio config needs to be set to an audio file instead of default as in local machine it cannot default to a speaker in this case. Try adding the following to update audio_config

        file_name = "outputaudio.wav"
        file_config = speechsdk.audio.AudioOutputConfig(filename=file_name)
        speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=file_config)
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.