How do I use Google Speech API to access a file in Google Cloud Storage?

倖福魔咒の 提交于 2019-12-11 17:24:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!