saad samad
unread,Oct 28, 2024, 1:23:49 PM10/28/24Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium-dev, Рустам Астафеев, Chaitanya Garikipati, jyant...@gmail.com
hey i am using the speech api and not the cloud speech api with my C# code but i am getting a bad request what could be the reason
here's my code
public static async Task<string> RecognizeSpeechWithApiKeyAsync(string audioFilePath, string apiKey)
{
if (!File.Exists(audioFilePath))
{
throw new FileNotFoundException($"Audio file not found: {audioFilePath}");
}
var audioData = Convert.ToBase64String(File.ReadAllBytes(audioFilePath));
Console.WriteLine($"Audio Data Length: {audioData.Length}");
var requestBody = new
{
config = new
{
encoding = "LINEAR16",
sampleRateHertz = 16000,
languageCode = "en-US"
},
audio = new
{
content = audioData
}
};
var requestJson = JsonConvert.SerializeObject(requestBody);
var requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
var requestUri = $"
https://speech.googleapis.com/v1/speech:recognize?key={apiKey}";
var response = await httpClient.PostAsync(requestUri, requestContent);
response.EnsureSuccessStatusCode();
var jsonResponse = await response.Content.ReadAsStringAsync();
dynamic result = JsonConvert.DeserializeObject(jsonResponse);
return result.results[0].alternatives[0].transcript;