skip to Main Content

I am working with PHP/Laravel/Inertia to connect with Azure’s TTS for a project. I have been getting this consistent error for days with no solution. Any help will be appreciated. Here is the error

-reasonPhrase: "Data at the root level is invalid. Line 1, position 1."

-statusCode: 400

Here is my code

$content = "I'm excited to try text to speech!";

$response = Http::withOptions([
    'debug'=>true,
    'verify'=>false,
])->withToken($this->getTTSAuthToken())->withHeaders([
    'Content-Type' => 'application/ssml+xml',
    'X-Microsoft-OutputFormat' => 'riff-24khz-16bit-mono-pcm',
    'User-Agent' => 'content-development',
    'Content-Length' => strlen($content),
])->post("https://eastus.tts.speech.microsoft.com/cognitiveservices/v1",
"<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='Male' name='en-US-ChristopherNeural'>$content</voice></speak>"
);

I know the error means something is wrong with the data I am sending to the TTS api, however, I cannot figure out what is wrong. According to Azure’s website, status 400 means missing parameter, however, I have supplied all necessary parameters and tried several other variations.

2

Answers


  1. Chosen as BEST ANSWER

    The solution is: Do not use Http that comes with Laraavel. Write your own curl function.

    Writing my own curl function was the solution, I guess Http adds some other things to the post request.


  2. Something is wrong with your SSML? To use the voice ChristopherNeural and let it say "Hello Vy Do" I use this SSML string and it’s working. The attribute Gender and Language is not required.

    <speak version="1.0" 
    xmlns="http://www.w3.org/2001/10/synthesis" 
    xml:lang="string" 
    xmlns:mstts="https://www.w3.org/2001/mstts">
    <voice  name="en-US-ChristopherNeural">
    Hello Vy Do </voice> </speak>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search