· 6 years ago · Sep 07, 2019, 06:12 PM
1/// <summary>
2 /// Send byte array audio to yandex.speechkit
3 /// </summary>
4 /// <returns>text from audio</returns>
5 public static string YandexApiRecognition(byte[] audio)
6 {
7 using (var client = new HttpClient())
8 {
9 //enter your api key for yandex.speechkit
10 var apiKey = "";
11 client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
12 apiKey);
13 client.DefaultRequestHeaders.TransferEncodingChunked = true;
14
15 var content = new ByteArrayContent(audio);
16 //TODO: do it async.
17 var response = client
18 .PostAsync(
19 "https://stt.api.cloud.yandex.net/speech/v1/stt:recognize?topic=general&folderId=b1g4evj46j4c9956t0n8&lang=ru-RU",
20 content).Result;
21 return response.Content.ReadAsStringAsync().Result;
22 }
23 }