I am trying to get audio from Google Text-To-Speech to Twilio MULAW/8000.
It is all working fine apart from a click when the audio starts playing.
I see that Google sends a WAV header with the MULAW base64. How can I remove the WAV header from the payload. My code is below.
This plays / works fine, I just want to remove the click sound when the audio starts playing. I think removing the WAV header should do the trick.
use Google\Cloud\TextToSpeech\V1\AudioConfig;
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
$textToSpeechClient = new TextToSpeechClient();
$input = new SynthesisInput();
$input->setText('This is my test audio');
$voice = new VoiceSelectionParams();
$voice->setLanguageCode('en-US');
$audioConfig = new AudioConfig();
$audioConfig->setAudioEncoding(AudioEncoding::MULAW);
$audioConfig->setSampleRateHertz(8000);
$resp = $textToSpeechClient->synthesizeSpeech($input, $voice, $audioConfig);
$audioContent = $resp->getAudioContent();
$TheBase64Audio = base64_encode($audioContent);
As mentioned in the "WAVE File Format Analysis" of this article:
From this table, it is identified that the WAV header is 44 bytes long, you may skip or remove the first 44 to omit it.