[英]C# Speech To Text with Google API
I want to convert speech to text using Google Api 'speech-to-text'.我想使用 Google Api 'speech-to-text' 将语音转换为文本。 it worked when I took the example file but doesn't when I choose a file from local
当我使用示例文件时它有效,但当我从本地选择文件时无效
that's my code:那是我的代码:
using Google.Cloud.Speech.V1;
using System;
namespace SpeechToTextApiDemo
{
public class Program
{
public static void Main(string[] args)
{
var speech = SpeechClient.Create();
var config = new RecognitionConfig
{
Encoding = RecognitionConfig.Types.AudioEncoding.Flac,
SampleRateHertz = 16000,
LanguageCode = LanguageCodes.Hebrew.Israel,
EnableWordTimeOffsets = true
};
var audio = RecognitionAudio.FromStorageUri("gs://cloud-samples-tests/speech/brooklyn.flac");
var response = speech.Recognize(config, audio);
foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
Console.WriteLine($"Transcript: { alternative.Transcript}");
Console.WriteLine("Word details:");
Console.WriteLine($" Word count:{alternative.Words.Count}");
foreach (var item in alternative.Words)
{
Console.WriteLine($" {item.Word}");
Console.WriteLine($" WordStartTime: {item.StartTime}");
Console.WriteLine($" WordEndTime: {item.EndTime}");
}
}
}
}
}
}
Thank you!谢谢!
You have two options:您有两个选择:
https://cloud.google.com/speech-to-text/docs/basics#speech_requests https://cloud.google.com/speech-to-text/docs/basics#speech_requests
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.