You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creating a Text to Speech android app in Xamarin.Forms with the Bing Speech API
Challenge:
Create an android application with Xamarin.Forms to take record audio and display the display what you said using the Bing Speech API.
Set up:
Download and install Visual Studio for your platform.
Download or clone the repository and navigate to the correct start files and open SpeechToText.sln in Visual Studio. The starter solution is a Xamarin.Forms solution which has the following Nuget packages installed and ready for use:
On the RecordButton click event, use the AudioRecorderSerivce instance to record audio.
Api
To send a request, you will need to request a Jason WebToken using your free subscription key.
Create an instance of an HttpClient (save it in a class-wide variable for re-use) and add your subscription key to the DefaultRequestHeader as an "Ocp-Apim-Subscription-Key".
Send a PostAsync request to "https://api.cognitive.microsoft.com/sts/v1.0/issueToken" without a body. The content of the result can be read as a string, which is your Bearer token. Now you can make the request to the Bing Api and send your audio file:
First set your required bearer token to the HttpClient instance DefaultRequestHeaders.Authorization by setting it to a new AuthenticationHeaderValue.
Create a new StreamContent instance with the Stream of the recorded audiofile.
Set the Content-Type Headers of the streamcontent instance to the correct audio format: "audio/wav;codec="audio/pcm";samplerate=16000".
Send a PostAsync request to the correct http endpoint and pass in the StreamContent instance. Await and read the content of the response as a string.
Finally, update the label for the result text with the response and test your app!