kxxt / aspeak

A simple text-to-speech client for Azure TTS API.
MIT License
494 stars 57 forks source link

400 error #87

Closed mm3509 closed 6 months ago

mm3509 commented 6 months ago

I've been using the Python SDK, but due to https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/2204 and https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/2048, I am moving to REST.

I installed aspeak and tried the sample code, e.g.:

        service = aspeak.SpeechService(
            region=SPEECH_REGION,
            key=get_key()
        )
        print(ssml)
        service.speak_ssml(ssml)

I get this error:

$ python3 tts_microsoft.py
<speak>Olá crianças! Como se sentem? Eu sinto-me contente.</speak>
Traceback (most recent call last):
  File "~/tts_microsoft.py", line 150, in synth
    service.speak_ssml(ssml)
OSError: unified synthesizer error: an invalid request is constructed or 400 status reported by the server

Caused by:
   0: rest synthesizer error: an invalid request is constructed or 400 status reported by the server
   1: HTTP status client error (400 Bad Request) for url (https://westeurope.tts.speech.microsoft.com/cognitiveservices/v1)

Location:
    src/synthesizer/unified.rs:60:62

I get the same error if I use .synthesize_ssml, with or without the output argument.

How can I fix this error and run Microsoft's text-to-speech with aspeak and REST?

kxxt commented 6 months ago

400 error indicates your ssml is not valid. Please read the Microsoft documentation about how to construct SSML: https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-structure

mm3509 commented 5 months ago

Correct! Once I fixed the SSML to Microsoft's standards, instead of generic SSML, it worked. Thanks! For reference, this SSML failed:

<speak>Olá crianças! Como se sentem? Eu sinto-me contente.</speak>

This SSML worked:

<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xmlns:mstts='https://www.w3.org/2001/mstts' xml:lang='pt-pt'><voice name='pt-PT-RaquelNeural'>Olá crianças! Como se sentem? Eu sinto-me contente.</voice></speak>
mm3509 commented 5 months ago

I found this package by chance. I was using the official Python SDK, but out of nowhere it started failing with an OpenSSL issue unsolved for 8 months, also referenced here. The first issue suggests:

I think at this point your best bet is trying to migrate to the Azure Cognitive Services REST API, as Microsoft clearly has no interest or resources in maintaining the native SDK anymore.

I hope this helps someone find this package too. Thanks @kxxt for sharing this great piece of work and making my day!