Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google TTS no longer works. #442

Open
xd009642 opened this issue Sep 18, 2023 · 8 comments
Open

Google TTS no longer works. #442

xd009642 opened this issue Sep 18, 2023 · 8 comments

Comments

@xd009642
Copy link

It doesn't matter what the request is we get responses like this:

Invalid byte 47, offset 18110. at line 3 column 1: {
    "audioContent": "UklGRuyoAQBXQVZFZm10IBAAAAABAAEA8FUAAOCrAAACABAAZGF0YcioAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

A snippet of the code, the error message comes from the result of awaiting .doit().

        let voice = VoiceSelectionParams {
            language_code: Some(language.to_string()),
            name: params.voice.clone(),
            ssml_gender: None,
            custom_voice: None,
        };

        // Set to s16le PCM https://cloud.google.com/speech-to-text/docs/encoding this returns a
        // wav file
        let audio = AudioConfig {
            audio_encoding: Some("LINEAR16".to_string()),
            effects_profile_id: None,
            pitch: params.pitch,
            sample_rate_hertz: Some(params.sample_rate as _),
            speaking_rate: params.speed,
            volume_gain_db: None,
        };

        self.tts
            .text()
            .synthesize(SynthesizeSpeechRequest {
                audio_config: Some(audio),
                input: Some(input),
                voice: Some(voice),
            })
            .doit()
            .await
@xd009642
Copy link
Author

Okay and we've done some bisecting and found that images made with version 3.1.0 work and it's just the 5.0.3 image that is broken.

@Byron
Copy link
Owner

Byron commented Sep 19, 2023

Thanks for reporting! I think there was a change related to the way certain kinds of data are represented. It should be possible to find this commit and maybe make it apply only to certain APIs. On the other hand, maybe there is an updated version of TTS available that would work with these changes, too.

@xd009642
Copy link
Author

I had a brief look for updates and didn't see any (but the google docs are pretty poor for finding this kind of info). It seems it's having trouble when checking the base64 response, but as it doesn't decode it and leaves that to me the user such a check seems kind of worthless? Like I have to check the result when converting it to bytes anyway - if this client won't decode the base64 for me why check it 🤷‍♂️

@xd009642
Copy link
Author

Okay I've done a bit of bisecting and can confirm the issue isn't present in 4.x and was introduced in 5.x. We're rolling back for now but I'm willing to help PR a change for this if it could expedite things, I just need pointing in the right direction 👀

@Byron
Copy link
Owner

Byron commented Sep 19, 2023

I recommend to use the local source of the crate in question to make it editable, and compare the working version and the non-working one. They will be close enough to make that possible. From there a local fix can be conceived and tested, and with it I can certainly be a guide to get a more permanent fix done, by some means supported by the generator. After all, per-API overrides are possible, should the fix be very specific.

Please also note that generally there should be a better way than using these crates, it's astonishing that Google doesn't support Rust officially yet.

@emarcotte
Copy link

Think I'm facing something similar with the secret manager secret access endpoint. Interesting thing I've found so far (haven't figured out WHY yet) is that if you handle the JsonDecodeError, take the payload and pass it thru serde_json::from_str it will decode just fine. Must be some encoding parameters somewhere.

@emarcotte
Copy link

emarcotte commented Sep 26, 2023

Ahha. It seems like the payload data was previously String and now its Vec<u8> going between v4 and v5. There's an encoder for base64 bytes, which I think is trying to use the 'url safe' variant of the encoding on the payload field. For me there's a + symbol in the text, which suggests I think that its not a url-safe encoding? Its possible this is related to #379.

Currently trying to find a reference somewhere for what encoding variant google uses.

@emarcotte
Copy link

emarcotte commented Sep 26, 2023

I can see some reference online (eg here https://stackoverflow.com/questions/28100601/decode-url-safe-base64-in-javascript-browser-side) that some APIs are URL safe which might indicate that an API-by-API choice is necessary for how to decode these values... grumble. If I find more I will post here.

emarcotte pushed a commit to emarcotte/google-apis-rs that referenced this issue Sep 26, 2023
Byron#442 flags an issue where
some APIs respond with non-valid base64 bytes values for the "URL safe"
flavor of configuration.

This adds support for a "standard" wrapper adjacent to the URL safe one
with the intention of finding a way to flag which structures should use
which configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants