Я хочу реализовать потоковое распознавание голоса на C # на GRPC, но у меня есть только API-ключ
этот тип ключа -> https://cloud.google.com/docs/authentication/api-keys
.на других языках (android, IOs) они могут «перехватывать» и добавлять заголовок с ключом, например:
Metadata.Key.of («x-goog-api-key», «value»);
как я могу сделать то же самое НО в c #?
мой код, если он необходим по любой причине.
public static async Task<object> StreamingRecognizeAsync(Stream audio)
{
var speech = SpeechClient.Create();
var streamingCall = speech.StreamingRecognize();
// Write the initial request with the config.
await streamingCall.WriteAsync(
new StreamingRecognizeRequest()
{
StreamingConfig = new StreamingRecognitionConfig()
{
Config = new RecognitionConfig()
{
Encoding =
RecognitionConfig.Types.AudioEncoding.Linear16,
SampleRateHertz = 16000,
LanguageCode = "en",
},
InterimResults = true,
}
});
// Print responses as they arrive.
Task printResponses = Task.Run(async () =>
{
while (await streamingCall.ResponseStream.MoveNext(
default(CancellationToken)))
{
foreach (var result in streamingCall.ResponseStream
.Current.Results)
{
foreach (var alternative in result.Alternatives)
{
Console.WriteLine(alternative.Transcript);
}
}
}
});
var buffer = new byte[32 * 1024];
int bytesRead;
while ((bytesRead = await audio.ReadAsync(
buffer, 0, buffer.Length)) > 0)
{
await streamingCall.WriteAsync(
new StreamingRecognizeRequest()
{
AudioContent = Google.Protobuf.ByteString
.CopyFrom(buffer, 0, bytesRead),
});
await Task.Delay(500);
};
await streamingCall.WriteCompleteAsync();
await printResponses;
return 0;
}
Большое спасибо