How to convert text string to speech sound

后端 未结 6 672
無奈伤痛
無奈伤痛 2020-12-07 14:12

I am looking for a way to convert text(string) in ENG to speech(sound) in c#. do anyone know for a way or some open-source lib that can help me with this task?

6条回答
  •  感情败类
    2020-12-07 14:44

    Recently Google published Google Cloud Text To Speech.

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

    Nuget: Install-Package JH.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);
    

提交回复
热议问题