google-text-to-speech

Google Text-to-Speech API 400 error for specific paragraph


I have an integration set up with Google TTS generating audio for a daily Bloomberg email newsletter. It's been working reliably, but I recently received a 400 error for a specific group of sentences:

"message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT

Sending POST to https://cloud.google.com/text-to-speech/docs/reference/rest/v1/text/synthesize with this payload:

{
    "input": {
        "text": "Still it hangs together in a rough schematic way, which means you can try it in thecryptomarket. Crypto, particularly decentralized finance, has some key advantages for this, including:\n\n * Weird and fragmented liquidity, so that you can trade with yourself on a futures exchange, and you can move the price of a token a lot on the spot market;\n * A love of mechanical rules and automated markets, so that if your X position spikes from $1 million to $100 million, some decentralized finance platform will say “yup, now it’s worth $100 million, so it’s good collateral for a $40 million loan”; and\n * A presumption of anonymity, so exchanges will let you trade with yourself, and won’t be able to come after you for your losses, since they just have some anonymous wallet addresses."
    },
    "voice": {
        "name": "en-US-Neural2-A",
        "languageCode": "en-US"
    },
    "audioConfig": {
        "pitch": -4,
        "speakingRate": 1.2,
        "audioEncoding": "MP3"
    }
}

I've confirmed this behavior is consistent in Google's API explorer, so I think I've isolated the text content itself as the source of the error. I eliminated unescaped characters as a cause by trying a no-symbol version of the text that still failed. API documentation hasn't yielded any clues on allowable characters or other requirements.

The weirdest thing is that the text above works if I delete either the first sentence or the last sentence. Is Google checking the content itself for prohibited phrases or something???

Any other ideas to resolve this error?


Solution

  • Neural languages seems to be more strict on the ssml. You have to include the speak tag. SSML speak

    {
        "input": {
            "text": "<speak>Still it hangs together in a rough schematic way, which means you can try it in thecryptomarket. Crypto, particularly decentralized finance, has some key advantages for this, including:\n\n * Weird and fragmented liquidity, so that you can trade with yourself on a futures exchange, and you can move the price of a token a lot on the spot market;\n * A love of mechanical rules and automated markets, so that if your X position spikes from $1 million to $100 million, some decentralized finance platform will say “yup, now it’s worth $100 million, so it’s good collateral for a $40 million loan”; and\n * A presumption of anonymity, so exchanges will let you trade with yourself, and won’t be able to come after you for your losses, since they just have some anonymous wallet addresses.<\speak>"
        },
        "voice": {
            "name": "en-US-Neural2-A",
            "languageCode": "en-US"
        },
        "audioConfig": {
            "pitch": -4,
            "speakingRate": 1.2,
            "audioEncoding": "MP3"
        }
    }