How can I use google text to speech api in windows form?

前端 未结 2 1175
青春惊慌失措
青春惊慌失措 2021-01-01 07:44

I want to use google text to speech in my windows form application, it will read a label. I added System.Speech reference. How can it read a label with a button click event?

2条回答
  •  不思量自难忘°
    2021-01-01 08:21

    I know this question is a bit out of date but recently Google published Google Cloud Text To Speech API.

    .NET Client version of Google.Cloud.TextToSpeech can be found here: https://github.com/jhabjan/Google.Cloud.TextToSpeech.V1

    Here is short example how to use the client:

    GoogleCredential credentials =
        GoogleCredential.FromFile(Path.Combine(Program.AppPath, "jhabjan-test-47a56894d458.json"));
    
    TextToSpeechClient client = TextToSpeechClient.Create(credentials);
    
    SynthesizeSpeechResponse response = client.SynthesizeSpeech(
        new SynthesisInput()
        {
            Text = "Google Cloud Text-to-Speech enables developers to synthesize natural-sounding speech with 32 voices"
        },
        new VoiceSelectionParams()
        {
            LanguageCode = "en-US",
            Name = "en-US-Wavenet-C"
        },
        new AudioConfig()
        {
            AudioEncoding = AudioEncoding.Mp3
        }
    );
    
    string speechFile = Path.Combine(Directory.GetCurrentDirectory(), "sample.mp3");
    
    File.WriteAllBytes(speechFile, response.AudioContent);
    

提交回复
热议问题