Hey guys! I’m sending a post request to the Bing speech API in order to convert text to speech. I’m using for that the UnityWebRequest to send my HTTP POST request with headers… this is the code :
public IEnumerator Synthesize(string text)
{
var synReq = UnityWebRequest.Post(synthesizeUri, text);
synReq.SetRequestHeader("Content-Type", "application/ssml+xml");
synReq.SetRequestHeader("X-Microsoft-OutputFormat", "riff-16khz-16bit-mono-pcm");
synReq.SetRequestHeader("X-Search-AppId", "07D3234E49CE426DAA29772419F436CA");
synReq.SetRequestHeader("X-Search-ClientID", "1ECFAE91408841A480F00935DC390960");
synReq.SetRequestHeader("User-Agent", "Dorot");
synReq.SetRequestHeader("Authorization", "Bearer " + accessToken);
var synRes = synReq.SendWebRequest();
yield return synRes;
byte[] byteData = synReq.downloadHandler.data;
//How to covnert byteData to and audioClip ?
}
Using the WWW class and to get the audio from the HTTP response, i used the GetAudioClip()
function as the following code shows, and it worked perfectly.
IEnumerator DownloadAudio()
{
string googleUrl = "http://translate.google.com/translate_tts?ie=UTF-8&total=1&idx=0&textlen=1024&client=tw-ob&q=+"+ "Hello%20how%20are%20you" + "&tl=En-gb";
WWW www = new WWW (googleUrl );
yield return www;
audioSource.clip = www.GetAudioClip (false, true, AudioType.MPEG);
audioSource.Play ();
}