Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static async Task<Stream> Upload(string modelString, byte[] audioFile)
- {
- HttpContent modelContent = new StringContent(modelString);
- HttpContent partContent = new StringContent("audio/wav");
- HttpContent continuousContent = new StringContent("true");
- HttpContent audioContent = new ByteArrayContent(audioFile);
- string actionUrl = "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize";
- using (var client = new HttpClient())
- {
- var byteArray = new UTF8Encoding().GetBytes("<username>:<password>");
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
- using (var formData = new MultipartFormDataContent())
- {
- formData.Add(modelContent, "model");
- formData.Add(partContent, "audio/wav");
- formData.Add(continuousContent, "continuous");
- formData.Add(audioContent, "file1", "file1.wav");
- var response = await client.PostAsync(actionUrl, formData);
- if (!response.IsSuccessStatusCode)
- {
- return null;
- }
- return await response.Content.ReadAsStreamAsync();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement