gpt4 book ai didi

c# - 将语音转换为文本 C#

转载 作者:太空宇宙 更新时间:2023-11-03 12:12:27 24 4
gpt4 key购买 nike

我正在尝试使用 google API 将语音转换为文本,这里有一个测试页 https://cloud.google.com/speech-to-text/您可以在其中验证您的音频是否已转换为文本,我正在介绍我的音频,对于此页面,如果它成为文本,但我正在使用我的程序提供的服务,但我没有设法做到这一点,则会显示以下错误:“损坏的文件再次发送音频:状态(StatusCode = InvalidArgument,Detail =\”无效识别\'config\':错误的采样率赫兹。\“)”

我的代码如下:

        string pathAudio = CreateAudio(Base64Audio);
var speech = SpeechClient.Create();

var response = speech.Recognize(new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
LanguageCode = "es-MX",
}, RecognitionAudio.FromFile(pathAudio));

foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
resultado = alternative.Transcript;
}
}
return resultado;

他们知道这可能正在发生。

最佳答案

The documentation提及:

sampleRateHertz - (required) specifies the sample rate (in Hertz) of the supplied audio. (For more information on sample rates, see Sample Rates below.) The sampleRateHertz field is optional for FLAC and WAV files where the sample rate is included in the file header.

所以问题可能是缺少 SampleRateHertz 配置属性,但如果您尝试发送 WAV 文件(或 FLAC),则 Base64Audio 可能有问题或 CreateAudio() 方法 - 因为 API 显然无法检测采样率。

关于c# - 将语音转换为文本 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51431697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com