1

I would like to use the google Text to speech API with a MULAW 8Khz output audio format. I am using the code provided by Google :

    const text = 'Texte que vous souhaitez vocaliser'
    const outputFile = 'testJaf.ulaw';
    const languageCode = 'fr-FR';
    const ssmlGender = 'FEMALE';
    const sampleRateHertz = 8000;
    const audioEncoding = "MULAW";

    async function synthesizeWithEffectsProfile() {
        // Add one or more effects profiles to array.
        // Refer to documentation for more details:
        // https://cloud.google.com/text-to-speech/docs/audio-profiles
        //sampleRateHertz:sampleRateHertz,
        const effectsProfileId = ['telephony-class-application'];
    
        const request = {
          input: {text: text},
          voice: {languageCode: languageCode, ssmlGender: ssmlGender},
          audioConfig: {audioEncoding: audioEncoding, sampleRateHertz:sampleRateHertz, effectsProfileId: effectsProfileId},
        };
    
        const [response] = await speechClient.synthesizeSpeech(request);
        const writeFile = util.promisify(fs.writeFile);
        await writeFile(outputFile, response.audioContent, 'binary');
        console.log(`Audio content written to file: ${outputFile}`);
      }

With or without the sampleRateHertz parameter and only for MULAW ( MP3 and OGG are ok ) I get an encoding type error:

(node:2256816) UnhandledPromiseRejectionWarning: Error: 3 INVALID_ARGUMENT: Invalid encoding type.
at Object.callErrorFromStatus (/root/node-red-vb/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
at Object.onReceiveStatus (/root/node-red-vb/node_modules/@grpc/grpc-js/build/src/client.js:179:52)
at Object.onReceiveStatus (/root/node-red-vb/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:336:141)
at Object.onReceiveStatus (/root/node-red-vb/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:299:181)
at /root/node-red-vb/node_modules/@grpc/grpc-js/build/src/call-stream.js:145:78
at processTicksAndRejections (internal/process/task_queues.js:79:11)

Can anyone help me? Do I need another parameter to make the MULAW type work?

jaf
  • 21
  • 2

0 Answers0