问题
I am using Visual Studio 2019 on Windows 10 for a .NET Console C# project using Google Speech API.
I have the following code:
class Program
{
static void Main(string[] args)
{
var URI = "https://speech.googleapis.com/v1/speech:recognize?key=AIzaSyANbpQ1iy-Ced72r7xgPVHuNZI5FAVIPjY&audio=audio.flac";
Console.WriteLine("Start!");
AsyncRecognizeGcs(URI);
Console.WriteLine("End.");
}
static object AsyncRecognizeGcs(string storageUri)
{
var speech = SpeechClient.Create();
var longOperation = speech.LongRunningRecognize(new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Flac,
SampleRateHertz = 44100,
AudioChannelCount = 2,
LanguageCode = "en",
}, RecognitionAudio.FromStorageUri(storageUri)); // error here
longOperation = longOperation.PollUntilCompleted();
var response = longOperation.Result;
foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
Console.WriteLine($"Transcript: { alternative.Transcript}");
}
}
return 0;
}
}
I have a file named "long.flac" in a bucket in Google Cloud Storage. I have not written the code to point to that file. How do I write code to access that file?
Here is documentation to use the POST REST API to Google Speech API using json representation requests. How would I integrate that information with what I already have?
Basically, I need to know the value of the variable URI in my code.
回答1:
The uri is in the format of
gs://bucketname/path/filename
I wish I knew sooner that I had free chat support with my free account with Google Cloud Platform.
来源:https://stackoverflow.com/questions/56707803/how-do-i-use-google-speech-api-to-access-a-file-in-google-cloud-storage