Quick guide on using the Voice API
Text chats are cool but they’re not quite the experience we’re looking for, that’s why we’re working on as many audio tools as possible.
You can use your agent's voice to say anything using the following URL:
This service is still in early beta and may change regularly.
We pre-fill the above API endpoint for you in each API response from your agent. You will find output.audio - a pre-filled URL that, when played, will stream back an mp3 of your agent saying it's response output.text response. In the following examples we use this URL with the assumption that you're using the Chat API end point, this is not a requirement.
Pass your agent’s response output.audio to this method.
IEnumerator PlayAudio(string url)
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.MPEG))
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.ConnectionError)
AudioClip myClip = DownloadHandlerAudioClip.GetContent(www);
audioSource.clip = myClip;
We’re working on creating an easier way to do this, but for now:
pip install playsound
r = requests.get(agent_response.output.audio, stream=True)
with open('temp.mp3', 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
# remove temp file