textToSpeech by google cloud Api
# 🤝help
After successfully executing a code to generate audio response from the API, cloud textToSpeech response in base64. How do i make this play as an audio in my workflow
Hey @incalculable-judge-70838, while you can add an audio card and use a URL for the audio source, I'm not sure there's a way to auto-play the clip.
Thanks for your insight but how do you think i can extract the audio source Url and use for a audio card
Using the response i got in base64 from the textToSpeech API
Meanwhile i will give a shot using the screenshot you just shared and give you a feedback
the API response for your TTS API has a field
. In that same code block, you can make a new workflow var and fill it with that value like:
Copy code
workflow.audioContent = `${endpoint}${response.audioContent}`
Note that the value is a relative URL (it starts with // instead of https://) so that means it needs to be appended onto whatever endpoint it is that you're querying. Check out that service's API documentation, they probably have an example you can copy/paste from.
Im using google cloud textToSpeech can i share the code i executed?
const textToSpeech = async (text, languageCode = 'en-US') => { const url = 'https://texttospeech.googleapis.com/v1/text:synthesize'; const apiKey = 'API-Key'; // Replace with your actual API key const response = await axios.post( url, { input: { text }, voice: { languageCode }, audioConfig: { audioEncoding: 'MP3' } }, { headers: { 'X-Goog-Api-Key': apiKey } } ); const audioContent = _.get(response, 'data.audioContent'); return audioContent; }; // Usage: const audioContent = await textToSpeech('fine thanks');
I will also share the screenshot of the debugger log
huh, looking at the documentation, the returned value is a string of bytes, not a URL.... I don't know how to process that 😅
yeah I have no idea, sorry 😅
Oh yeah! That is absolutely correct!
Thanks for your time and insight
If you get any clue please do not hesitate to help or perharps if you have any textToSpeech API i can try out, please let me know
I will like to use this function for my project
hey were you able to find a solution to this? im running into the same problem
Not yet… had to switch to another provider of that function but still enjoying botpress otherwise and im looking forward to getting that the solution to the functionality here on botpress
ok nice! thanks for the quick response. if you dont mind sharing, what other provider did you use?