如何在 c# 中为 Google 语音识别 api 准备音频文件(wav 或 mp3)?
How to prepare audio files (wav or mp3) for Google speech recognition api in c#?
String jsonRequest = "{\"config\": {\"languageCode\":\"en-US\"},\"audio\": {\"content\": \"" + base64Content+ "\"}}";
String str = "";
var speech = SpeechClient.Create();
var response =
speech.Recognize(RecognizeRequest.Parser.ParseJson(jsonRequest));
foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
Console.WriteLine(alternative.Transcript);
str += alternative.Transcript;
}
}
此代码在处理单声道 .wav 文件时运行良好,但在处理立体声文件时会抛出异常。异常显示
Status(StatusCode=InvalidArgument, Detail="Must use single channel (mono) audio, but WAV header indicates 2 channels.")
所以,我的问题是如何添加对立体声文件的支持?如何在 C# 中将多声道音频转换为单声道?我已经试过 this answer 所以请不要参考它。它不起作用。
String jsonRequest = "{\"config\": {\"languageCode\":\"en-US\"},\"audio\": {\"content\": \"" + base64Content+ "\"}}";
String str = "";
var speech = SpeechClient.Create();
var response =
speech.Recognize(RecognizeRequest.Parser.ParseJson(jsonRequest));
foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
Console.WriteLine(alternative.Transcript);
str += alternative.Transcript;
}
}
此代码在处理单声道 .wav 文件时运行良好,但在处理立体声文件时会抛出异常。异常显示
Status(StatusCode=InvalidArgument, Detail="Must use single channel (mono) audio, but WAV header indicates 2 channels.")
所以,我的问题是如何添加对立体声文件的支持?如何在 C# 中将多声道音频转换为单声道?我已经试过 this answer 所以请不要参考它。它不起作用。