- Home /
Question by
montacerdk · Apr 04, 2018 at 09:50 AM ·
c#wwwaudioclipwebrequestbytes
How to get audioclip from UnityWebRequest
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 ();
}
Comment
Answer by FlaSh-G · Apr 04, 2018 at 11:42 AM
You're looking for this:
https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestMultimedia.GetAudioClip.html
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Playing wav audio with integer samples 1 Answer
Upload files to a remote form using C# in Unity 2 Answers
Download multiple files from server 2 Answers