markokosticdev / cloud_text_to_speech_flutter

Single interface to Google, Microsoft, and Amazon Text-To-Speech.
https://pub.dev/packages/cloud_text_to_speech
BSD 2-Clause "Simplified" License
4 stars 2 forks source link

Unhandled Exception: 400: Bad Request A required parameter is missing, empty, or null. Or, the value passed to either a required or optional parameter is invalid. A common issue is a header that is too long. Bad Request #4

Closed alishahzad331 closed 1 week ago

alishahzad331 commented 10 months ago

When I passed the paramters to the TtsGoogle.convertTts function. I received the following error This is my parameter final text = 'Speech Service Text-to-Speech API is awesome!';

TtsParamsGoogle params = TtsParamsGoogle(
    voice: voice,
    audioFormat: AudioOutputFormatGoogle.mp3,
    text: text,
    rate: 'slow', // optional
    pitch: 'default' // optional
    );

and this is the error Unhandled Exception: 400: Bad Request A required parameter is missing, empty, or null. Or, the value passed to either a required or optional parameter is invalid. A common issue is a header that is too long. Bad Request

markokosticdev commented 10 months ago

Have you set the API key?

Example:

TtsGoogle.init(
      apiKey: "API-KEY", 
      withLogs: true);
alishahzad331 commented 10 months ago

Yes. The API key is set. But it is still not working.

RDRRdev commented 10 months ago

I was having the same issue and did some digging.

In the file src/google/ssml/ssml.dart, line 20, there is a missing '>' to close the 'speak' tag. I also think there is an issue with the variable insertion in that same block, but I ended up just deleting them entirely for my own purpose and didn't get to the bottom of what was going on.

markokosticdev commented 8 months ago

Fixed

himanshu-newstok commented 1 month ago

Facing same problem in flutter web in production. In debug mode it works perfectly but when deploying to netlify it gives below error.

Error in console:

POST https://texttospeech.googleapis.com/v1/text:synthesize 400 (Bad Request)
cE @ main.dart.js:42142
aC_ @ main.dart.js:244
(anonymous) @ main.dart.js:79611
(anonymous) @ main.dart.js:6028
$2 @ main.dart.js:38761
$1 @ main.dart.js:38755
akg @ main.dart.js:39680
GS @ main.dart.js:39683
$0 @ main.dart.js:39124
tR @ main.dart.js:6124
oa @ main.dart.js:39050
$0 @ main.dart.js:39095
aKW @ main.dart.js:6156
aL9 @ main.dart.js:6158
$1 @ main.dart.js:38705
childList (async)
$1 @ main.dart.js:38712
axJ @ main.dart.js:6163
jE @ main.dart.js:6249
eG @ main.dart.js:6175
O6 @ main.dart.js:47371
ra @ main.dart.js:47369
a0 @ main.dart.js:48358
t9 @ main.dart.js:48082
iB @ main.dart.js:48383
C3 @ main.dart.js:48091
hC @ main.dart.js:48075
(anonymous) @ main.dart.js:4796
a1A @ main.dart.js:48300
$2 @ main.dart.js:48312
U @ main.dart.js:38298
Kp @ main.dart.js:48307
TF @ main.dart.js:48305
jF @ main.dart.js:47434
aez @ main.dart.js:47428
Lt @ main.dart.js:47422
Fx @ main.dart.js:47412
BU @ main.dart.js:47410
a4h @ main.dart.js:47398
(anonymous) @ main.dart.js:4796
n6 @ main.dart.js:1652
aiJ @ main.dart.js:32416
(anonymous) @ main.dart.js:4797
o8 @ main.dart.js:32462
$1 @ main.dart.js:32708
$1 @ main.dart.js:32666
$1 @ main.dart.js:32465
aur @ main.dart.js:4622
aEt @ main.dart.js:6975
aJQ @ main.dart.js:8316
(anonymous) @ main.dart.js:8312
main.dart.js:4660 Uncaught 400: Bad Request A required parameter is missing, empty, or null. Or, the value passed to either a required or optional parameter is invalid. A common issue is a header that is too long. 
    at Object.c (https://663cfda222096c1b5fd3cfc3--startling-strudel-9db456.netlify.app/main.dart.js:4660:19)
    at https://663cfda222096c1b5fd3cfc3--startling-strudel-9db456.netlify.app/main.dart.js:44382:20
    at alZ.a (https://663cfda222096c1b5fd3cfc3--startling-strudel-9db456.netlify.app/main.dart.js:6028:63)
    at alZ.$2 (https://663cfda222096c1b5fd3cfc3--startling-strudel-9db456.netlify.app/main.dart.js:38761:14)
    at al5.$1 (https://663cfda222096c1b5fd3cfc3--startling-strudel-9db456.netlify.app/main.dart.js:38755:21)
    at aj3.akg (https://663cfda222096c1b5fd3cfc3--startling-strudel-9db456.netlify.app/main.dart.js:39680:34)
    at aj3.GS (https://663cfda222096c1b5fd3cfc3--startling-strudel-9db456.netlify.app/main.dart.js:39683:13)
    at agy.$0 (https://663cfda222096c1b5fd3cfc3--startling-strudel-9db456.netlify.app/main.dart.js:39124:11)
    at Object.tR (https://663cfda222096c1b5fd3cfc3--startling-strudel-9db456.netlify.app/main.dart.js:6124:40)
    at al.oa (https://663cfda222096c1b5fd3cfc3--startling-strudel-9db456.netlify.app/main.dart.js:39050:3)

Response from api call:

{
  "error": {
    "code": 400,
    "message": "Invalid SSML. Newer voices like Neural2 require valid SSML.",
    "status": "INVALID_ARGUMENT"
  }
}

My SSML:

<speak>
  <voice name="en-US-Standard-C">My name is TTS.</voice>
</speak>

It works in localhost perfectly but gives above error in production. And my api key do not have any restriction.

markokosticdev commented 1 month ago

What version of cloud_text_to_speech are you using? Have you upgraded?

himanshu-newstok commented 1 month ago

Latest version cloud_text_to_speech: ^2.3.0.I found the prblm, if we pass voice in the ssml like above ssml and also give neural voice using the voice property causes this problem. And why are you adding $1 in the text?

markokosticdev commented 1 month ago

Use this to set voice:

TtsParamsMicrosoft ttsParams = TtsParamsMicrosoft( voice: voice, audioFormat: AudioOutputFormatMicrosoft.audio48Khz192kBitrateMonoMp3, text: text, rate: 'slow', // optional pitch: 'default' // optional );

Please update to 2.3.2