I ended up using a post request with base64 of the audio file then added the Google api key in the request.
var base64 = Convert.ToBase64String(File.ReadAllBytes(file));
dynamic request = new
{
config = new
{
encoding = "LINEAR16",
sampleRateHertz = 8000,
languageCode = "en-US",
enableWordTimeOffsets = false
},
audio = new
{
content = base64
}
};
var json = JsonConvert.SerializeObject(request);
var requestJson = StringContent(json, Encoding.UTF8, "application/json");
var client = new HttpClient();
var speechToText = "";
var response = await client.PostAsync($"https://speech.googleapis.com/v1/speech:recognize?key=GOOGLE-KEY", requestJson);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var converted = JsonConvert.DeserializeObject<GcpSpeechApiResponseModel>(content);
if (converted != null) {
foreach (var result in converted.Results)
{
foreach (var alternative in result.Alternatives)
{
speechToText = speechToText + alternative.Transcript;
}
}
}
}
return speechToText;
implementation 'io.grpc:grpc-okhttp:1.38.0' implementation 'io.grpc:grpc-stub:1.38.0' compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+
– Caseate