Hi, I am trying to build a voice enabled interactive chat application on hololens. For speech to text conversion i am using Unity’s built-in class DictationRecognizer for now. But its perfomance is very poor.
When i try to use Bing REST API, i am getting error.
try
{
var token = auth.GetAccessToken();
Console.WriteLine("Token: {0}
", token);
Console.WriteLine("Request Uri: " + requestUri + Environment.NewLine);
HttpWebRequest request = null;
request = (HttpWebRequest)HttpWebRequest.Create(requestUri);
request.SendChunked = true;
request.Accept = @"application/json;text/xml";
request.Method = "POST";
request.ProtocolVersion = HttpVersion.Version11;
//request.Host = host;
request.ContentType = contentType;
request.Headers["Authorization"] = "Bearer " + token;
//request.UseDefaultCredentials = true;
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
using (fs = new FileStream(audioFile, FileMode.Open, FileAccess.Read))
{
/*
* Open a request stream and write 1024 byte chunks in the stream one at a time.
*/
byte[] buffer = null;
int bytesRead = 0;
using (Stream requestStream = request.GetRequestStream())
{
/*
* Read 1024 raw bytes from the input audio file.
*/
buffer = new Byte[checked((uint)Math.Min(1024, (int)fs.Length))];
while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) != 0)
{
requestStream.Write(buffer, 0, bytesRead);
}
// Flush
requestStream.Flush();
}
/*
* Get the response from the service.
*/
Console.WriteLine("Response:");
using (WebResponse response = request.GetResponse())
{
Console.WriteLine(((HttpWebResponse)response).StatusCode);
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
responseString = sr.ReadToEnd();
}
Console.WriteLine(responseString);
Console.ReadLine();
File.Delete(filePath);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.WriteLine(ex.Message);
Console.ReadLine();
File.Delete(filePath);
}