Closed mdumanoj closed 6 years ago
The sample in the sample
folder works for me. You need to provide the following arguments when running the application, as described here.
Yes. I can also run this code in Console Mode. But I want to develop a Web API which gets the file from post request and process the file to convert into Text. I am not getting any response there. Any help?
The sample program shows key steps how to interact with the SDK and the service. If the sample works for you, it means you can correctly talk to the speech service using the SDK. However, we do not know how your application is using the SDK. Have you checked whether any step is missing? What do you mean by "not getting any response"? Have you used Fiddler to check whether any requests have been sent to the speech service and what are the responses from the service? Is your application waiting for the recognition result?
I Created my application as a Web API, I am using this SDK in that. There I have one API which gets the audio file in the request and converts that file into text, prints that in Debug Statement. Here my Code is just waiting for Response Forever. Is there any additional configuration has to be done for Web API?
I Just Replaced Main Method like this and declared variables for arguments. I have run method and Partial run method, there I replaced Console statement to Debug Statement.
[HttpPost]
[Route("api/Speech/upload")]
public async Task<HttpResponseMessage> SpeechToText()
{
HttpResponseMessage response = null;
Debug.WriteLine("API Called...!");
if (!Request.Content.IsMimeMultipartContent())
{
return Request.CreateErrorResponse(HttpStatusCode.UnsupportedMediaType, "Media Type Not Supported");
}
string root = HttpContext.Current.Server.MapPath("~/App_Data/");
var provider = new MultipartFormDataStreamProvider(root);
try
{
await Request.Content.ReadAsMultipartAsync(provider);
MultipartFileData FileData = provider.FileData.First();
string destFileName = FileData.LocalFileName + Guid.NewGuid();
destFileName = destFileName.Replace(" ", "_");
string destinationPath = Path.Combine(root, destFileName) + ".wav";
File.Move(FileData.LocalFileName, destinationPath);
string fileName = FileData.Headers.ContentDisposition.FileName;
Debug.WriteLine("File Name :: " + fileName);
Debug.WriteLine("Dest File Path :: " + destinationPath);
// Process Audio File
this.Run(destinationPath, Locale, LongDictationUrl, SubscriptionKey).Wait();
response = Request.CreateResponse(HttpStatusCode.OK, "Success");
}
catch (Exception e)
{
Debug.WriteLine("Exception :: " + e);
}
return response;
}
@mdumanoj Have you used Fiddler to check whether any request is sent to the service? And any event handler OnPartialResult or OnRecognitionResult has been called in your application? The recognition respose is recevied from those event handlers.
Hey thank you for your help @zhouwangzw.
I just changed this line from this.Run(destinationPath, Locale, LongDictationUrl, SubscriptionKey).Wait();
to await this.Run(destinationPath, Locale, LongDictationUrl, SubscriptionKey);
Now I'm getting response in the Event Handler. Once again thank you so much for your prompt response and Appreciate it.
Need Samples for Web API. To upload the Audio file and convert that into Text. I tried out this example but I am not getting any response. But Desktop Client is working fine, printing transcript in the command line. It would be great If there is some more examples.