pgmichael / wavenet-for-chrome

Chrome extension that transforms highlighted text into high-quality natural sounding audio using Google Cloud's Text-to-Speech.
http://wavenet-for-chrome.com
MIT License
134 stars 50 forks source link

Replicating Wavenet-for-Chrome in Google TTS NodeJS #6

Closed g4spow closed 5 years ago

g4spow commented 5 years ago

This is brilliant, so handy.

Just a query regarding bitrate and overall quality. When using "Download as MP3" the quality from Wavenet-for-Chrome far exceeds what I am getting out of using the NodeJS version of Google Text-to-Speech.

https://github.com/pgmichael/wavenet-for-chrome/blob/master/js/background.js

I take it you are using LINEAR16 to create the better quality bitrate and then writing it as an MP3?

Here is my code:

    // Start the Google Text-to-Speech program   
    const client = new textToSpeech.TextToSpeechClient();

    const request = {
      input: { text: myMessage },
      // Select the language and SSML Voice Gender (optional)
      voice: { languageCode: langcode, name: voicename },
      // Select the type of audio encoding
      audioConfig: { audioEncoding: 'MP3' },
    };

    // Performs the Text-to-Speech request
    const [response] = await client.synthesizeSpeech(request);
    // Write the binary audio content to the temp
    const writeMP3File = util.promisify(fs.writeFile);
    await writeMP3File('/tmp/' + "tts.mp3", response.audioContent, 'binary');
    console.log('MP3 audio content written to temp');

This is what I get from using this Node code Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s

Can you help edit this code so I get the same top quality as I get when I use your plugin? (I use NodeJS for the bigger files)

pgmichael commented 5 years ago

Hi there, To be honest, I'm not very familiar with the Node client of Google's Cloud Text-to-Speech API. However, I believe simply changing the audioEncoding value in your request variable to 'LINEAR16' should do the trick.

If you need any further help, I advise you to open a ticket directly on the client's github repo. They might be able to offer you better support there.

Cheers!