Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK
MIT License
2.85k stars 1.84k forks source link

Irregular runtime error occurred when calling speak_ssml_async in python #1646

Closed flt6 closed 2 years ago

flt6 commented 2 years ago

Describe the bug An RuntimeError occurred while calling speak_ssml_async This error seemed to occurred randomly. Even if args and environment is absolutely same, it doesn't occur every time. Sometimes when I reboot the computer or test next day, the error doesn't occurred for hours. This error seems can't be catch through try.

To Reproduce Executing function tts with correct ssml and output file path for many times at the same time in windows may result in raising this error. File tts.py

from aspeak import SpeechToFileService,AudioFormat,FileFormat

provider=None
fmt=AudioFormat(FileFormat.MP3,-1)

def init():
    global provider
    provider=SpeechToFileService(locale="zh-CN",audio_format=fmt)

def tts(ssml:str,path:str):
    if provider is None:
        init()
    return provider.ssml_to_speech_async(ssml,path=path)  # type: ignore

Execute example (only for test):

from tts import tts
SSML_MODEL = '''<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="en-US">
    <voice name="zh-CN-YunyeNeural">
        <prosody rate="43%" pitch="0%">
            {}
        </prosody>
    </voice>
</speak>'''
for i in range(30):
    tts(SSML_MODEL.format(str(i)*500),str(i)+".mp3")
# And then use `get` for each instance of `tts`

Expected behavior

This is Traceback text (memory address 00007FFE37F772C4, 00007FFE37FC76A8, 00007FFE37FC87A8 is fixed for every time.)

CRITICAL: Traceback (most recent call last):
  ......
  File "E:\***\tts.py", line 17, in tts
    return provider.ssml_to_speech_async(ssml,path=path)  # type: ignore
  File "F:\ProgramData\Miniconda3\lib\site-packages\aspeak\api\api.py", line 110, in wrapper
    self._setup_synthesizer(kwargs['path'])
  File "F:\ProgramData\Miniconda3\lib\site-packages\aspeak\api\api.py", line 139, in _setup_synthesizer
    self._synthesizer = speechsdk.SpeechSynthesizer(self._config, self._output)
  File "F:\ProgramData\Miniconda3\lib\site-packages\azure\cognitiveservices\speech\speech.py", line 1598, in __init__
    self._impl = self._get_impl(impl.SpeechSynthesizer, speech_config, audio_config,
  File "F:\ProgramData\Miniconda3\lib\site-packages\azure\cognitiveservices\speech\speech.py", line 1703, in _get_impl
    _impl = synth_type._from_config(speech_config._impl, None if audio_config is None else audio_config._impl)
RuntimeError: Exception with an error code: 0x8 (SPXERR_FILE_OPEN_FAILED)
[CALL STACK BEGIN]

    > pal_string_to_wstring

    - pal_string_to_wstring

    - synthesizer_create_speech_synthesizer_from_config

    - synthesizer_create_speech_synthesizer_from_config

    - 00007FFE37F772C4 (SymFromAddr() error: 试图访问无效的地址。)

    - 00007FFE37FC76A8 (SymFromAddr() error: 试图访问无效的地址。)

    - 00007FFE37FC87A8 (SymFromAddr() error: 试图访问无效的地址。)

    - PyArg_CheckPositional

    - Py_NewReference

    - PyEval_EvalFrameDefault

    - Py_NewReference

    - PyEval_EvalFrameDefault

    - PyFunction_Vectorcall

    - PyFunction_Vectorcall

    - PyMem_RawStrdup

    - Py_NewReference

[CALL STACK END]

Version of the Cognitive Services Speech SDK 1.23.0

Platform, Operating System, and Programming Language

jhakulin commented 2 years ago

@yulin-li Could you please comment on this issue?

yulin-li commented 2 years ago

0x8 (SPXERR_FILE_OPEN_FAILED) means the audio file you are trying to write to is not available, the possible reasons are folder not existing, wrong permission, or this file is opened by another program.

Please note aspeak is a project that abuses azure TTS service by hacking the endpoint only for demo. Speech SDK is not designed to work with this demo endpoint. You need to get your own subscription and stop abusing.