コード例 #1
0
        public object AuthExplicit(string jsonPath)
        {
            System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Config", "gcp.json"));
            try
            {
                client = TextToSpeechClient.Create();
            }
            catch (Exception e)
            {
                Console.WriteLine($"Failed to initialise GCP TTS Client. Set GCP to 'false' in options.txt");
                Console.WriteLine("Press any key to see the exception...");
                Console.ReadKey();
                Console.WriteLine(e);
                Console.WriteLine("Press any key to quit...");
                Console.ReadKey();
                Environment.Exit(0);
            }
            var response = client.ListVoices("");

            List <string> voices = new List <string>();

            foreach (var voice in response.Voices)
            {
                Console.WriteLine($"{voice.Name} ({voice.SsmlGender}); Rate:{voice.NaturalSampleRateHertz} Language codes: {string.Join(", ", voice.LanguageCodes)}");
                voices.Add(voice.Name);
            }
            voicelist = voices;

            File.WriteAllText(voicelistfile, string.Empty);
            File.WriteAllLines(voicelistfile, voices);
            return(null);
        }
コード例 #2
0
        public Stream Test(string text, string language = "en-US")
        {
            var client = TextToSpeechClient.Create();

            // The input to be synthesized, can be provided as text or SSML.
            var input = new SynthesisInput
            {
                Text = text
            };

            // Build the voice request.
            var voiceSelection = new VoiceSelectionParams
            {
                LanguageCode = language,
                SsmlGender   = SsmlVoiceGender.Female
            };

            // Specify the type of audio file.
            var audioConfig = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Mp3
            };

            // Perform the text-to-speech request.
            var response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);

            // Write the response to the output file.
            using (var output = new MemoryStream())
            {
                response.AudioContent.WriteTo(output);
                return(output);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: eddiekart/WHACK2019
        static void Main(string[] args)
        {
            var client = TextToSpeechClient.Create();

            // The input to be synthesized, can be provided as text or SSML.
            var input = new SynthesisInput
            {
                Text = "Whoa whoa there, " + args[0] + "! Killer here is having a fit, so come back later"
            };

            // Build the voice request.
            var voiceSelection = new VoiceSelectionParams
            {
                LanguageCode = "en-US",
                SsmlGender   = SsmlVoiceGender.Neutral
            };

            // Specify the type of audio file.
            var audioConfig = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Mp3
            };

            // Perform the text-to-speech request.
            var response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);

            // Write the response to the output file.
            using (var output = File.Create("output3.mp3"))
            {
                response.AudioContent.WriteTo(output);
            }
            Console.WriteLine("Audio content written to file \"output3.mp3\"");
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: capnmidnight/Juniper
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;

            // credentials
            var userProfile = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
            var projectsDir = userProfile.CD("Projects");
            var keyFile     = projectsDir.CD("DevKeys").Touch("azure-speech.txt");
            var lines       = File.ReadAllLines(keyFile.FullName);

            client = new TextToSpeechClient(
                lines[0],
                lines[1],
                lines[2],
                new JsonFactory <Voice[]>(),
                new NAudioAudioDataDecoder(),
                new CachingStrategy
            {
                new FileCacheLayer(projectsDir)
            });

            using var p = player = new SoundPlayer();
            using var f = form = new SpeechGen();
            form.SetVoices(client.GetVoicesAsync().Result);

            form.GenerateSpeech += Form_GenerateSpeech;

            Application.Run(form);
        }
コード例 #5
0
        public static string Speak(string txt, QuestToSpeech.Voice voice, string filePath)
        {
            try {
                TextToSpeechClient client = TextToSpeechClient.Create();

                SynthesizeSpeechResponse res = client.SynthesizeSpeech(new SynthesizeSpeechRequest {
                    Input = new SynthesisInput {
                        Text = txt
                    },
                    Voice = new VoiceSelectionParams {
                        Name         = voice.Name,
                        LanguageCode = voice.LangCode,
                        SsmlGender   = voice.Gender == QuestToSpeech.Gender.Female ? SsmlVoiceGender.Female : SsmlVoiceGender.Male
                    },
                    AudioConfig = new AudioConfig {
                        AudioEncoding = AudioEncoding.Linear16
                    }
                });

                using (FileStream output = File.Create(filePath)) {
                    res.AudioContent.WriteTo(output);
                }
            } catch (Exception ex) {
                return(string.Format("GoogleTTS Exception: {0}", ex.InnerException == null ? ex.Message : ex.InnerException.ToString()));
            }

            return(null);
        }
コード例 #6
0
        public async Task Tts(string message)
        {
            var client = TextToSpeechClient.Create();

            var input = new SynthesisInput
            {
                Text = message.ToLower()
            };
            var voiceSelection = new VoiceSelectionParams
            {
                LanguageCode = "pl-PL",
                Name         = "pl-PL-Standard-C",
                SsmlGender   = SsmlVoiceGender.Female
            };
            var audioConfig = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Mp3,
                SpeakingRate  = 0.85
            };
            var response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);

            using (var output = File.Create(EnvVars.RoboMajkelTtsAudioFileLocation))
            {
                response.AudioContent.WriteTo(output);
            }

            IVoiceChannel channel     = (Context.User as IGuildUser)?.VoiceChannel;
            var           audioClient = await channel.ConnectAsync();

            await SendAsync(audioClient, EnvVars.RoboMajkelTtsAudioFileLocation);
        }
コード例 #7
0
        // [START tts_synthesize_text_file]

        // [START tts_synthesize_ssml_file]
        /// <summary>
        /// Creates an audio file from the input SSML file.
        /// </summary>
        /// <param name="ssmlFilePath">Path to SSML file</param>
        /// <remarks>
        /// Generates a file named 'output.mp3' in project folder.
        /// Note: SSML must be well-formed according to:
        ///    https://www.w3.org/TR/speech-synthesis/
        /// </remarks>
        public static void SynthesizeSSMLFile(string ssmlFilePath)
        {
            string text = File.ReadAllText(ssmlFilePath);

            var client   = TextToSpeechClient.Create();
            var response = client.SynthesizeSpeech(new SynthesizeSpeechRequest
            {
                Input = new SynthesisInput
                {
                    Ssml = text
                },
                // Note: voices can also be specified by name
                Voice = new VoiceSelectionParams
                {
                    LanguageCode = "en-US",
                    SsmlGender   = SsmlVoiceGender.Female
                },
                AudioConfig = new AudioConfig
                {
                    AudioEncoding = AudioEncoding.Mp3
                }
            });

            using (Stream output = File.Create("output.mp3"))
            {
                response.AudioContent.WriteTo(output);
            }
        }
コード例 #8
0
        public void SimpleExample()
        {
            // Sample: SynthesizeSpeech
            // Additional: SynthesizeSpeech(SynthesisInput,VoiceSelectionParams,AudioConfig,CallSettings)
            TextToSpeechClient client = TextToSpeechClient.Create();
            // The input can be provided as text or SSML.
            SynthesisInput input = new SynthesisInput
            {
                Text = "This is a demonstration of the Google Cloud Text-to-Speech API"
            };
            // You can specify a particular voice, or ask the server to pick based
            // on specified criteria.
            VoiceSelectionParams voiceSelection = new VoiceSelectionParams
            {
                LanguageCode = "en-US",
                SsmlGender   = SsmlVoiceGender.Female
            };
            // The audio configuration determines the output format and speaking rate.
            AudioConfig audioConfig = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Mp3
            };
            SynthesizeSpeechResponse response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);

            using (Stream output = File.Create("sample.mp3"))
            {
                // response.AudioContent is a ByteString. This can easily be converted into
                // a byte array or written to a stream.
                response.AudioContent.WriteTo(output);
            }
            // End sample
        }
コード例 #9
0
        public static int Main(string[] args)
        {
            // Create client
            TextToSpeechClient client = TextToSpeechClient.Create();

            // Initialize request argument(s)
            SynthesisInput input = new SynthesisInput
            {
                Text = "test",
            };
            VoiceSelectionParams voice = new VoiceSelectionParams
            {
                LanguageCode = "en-US",
            };
            AudioConfig audioConfig = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Mp3,
            };

            // Call API method
            SynthesizeSpeechResponse response = client.SynthesizeSpeech(input, voice, audioConfig);

            // Show the result
            Console.WriteLine(response);

            // Success
            Console.WriteLine("Smoke test passed OK");
            return(0);
        }
コード例 #10
0
        // [START tts_synthesize_ssml_file]

        // [START tts_synthesize_text_audio_profile]
        /// <summary>
        /// Creates an audio file from the text input, applying the specifed
        /// device profile to the output.
        /// </summary>
        /// <param name="text">Text to synthesize into audio</param>
        /// <param name="outputFile">Name of audio output file</param>
        /// <param name="effectProfileId">Audio effect profile to apply</param>
        /// <remarks>
        /// Output file saved in project folder.
        /// </remarks>
        public static int SynthesizeTextWithAudioProfile(string text,
                                                         string outputFile,
                                                         string effectProfileId)
        {
            var client   = TextToSpeechClient.Create();
            var response = client.SynthesizeSpeech(new SynthesizeSpeechRequest
            {
                Input = new SynthesisInput
                {
                    Text = text
                },
                // Note: voices can also be specified by name
                // Names of voices can be retrieved with client.ListVoices().
                Voice = new VoiceSelectionParams
                {
                    LanguageCode = "en-US",
                    SsmlGender   = SsmlVoiceGender.Female
                },
                AudioConfig = new AudioConfig
                {
                    AudioEncoding = AudioEncoding.Mp3,
                    // Note: you can pass in multiple audio effects profiles.
                    // They are applied in the same order as provided.
                    EffectsProfileId = { effectProfileId }
                }
            });

            // The response's AudioContent is binary.
            using (Stream output = File.Create(outputFile))
            {
                response.AudioContent.WriteTo(output);
            }

            return(0);
        }
コード例 #11
0
        public async Task <string> ObtainSpeechPathAsync(string text, string language = "en-US", bool male = true)
        {
            TextToSpeechClient client = TextToSpeechClient.Create();

            var response = await client.SynthesizeSpeechAsync(new SynthesizeSpeechRequest
            {
                Input = new SynthesisInput
                {
                    Text = text
                },
                Voice = new VoiceSelectionParams
                {
                    LanguageCode = language,
                    SsmlGender   = male ? SsmlVoiceGender.Male : SsmlVoiceGender.Female
                },
                AudioConfig = new AudioConfig
                {
                    AudioEncoding = AudioEncoding.Mp3
                }
            });

            var filename = Path.GetTempFileName();

            using (Stream output = File.Create(filename))
            {
                response.AudioContent.WriteTo(output);
                _logger.Log($"Audio content written to temp file '{filename}'");
            }

            return(filename);
        }
コード例 #12
0
        public static string GetVoices(ref QuestToSpeech.Voice[] voices)
        {
            try {
                List <QuestToSpeech.Voice> list     = new List <QuestToSpeech.Voice>();
                TextToSpeechClient         client   = TextToSpeechClient.Create();
                ListVoicesResponse         response = client.ListVoices(new ListVoicesRequest()
                {
                });                                                                                          // Performs the list voices request

                foreach (Voice voice in response.Voices)
                {
                    list.Add(new QuestToSpeech.Voice()
                    {
                        Name     = voice.Name,
                        Gender   = voice.SsmlGender == SsmlVoiceGender.Female ? QuestToSpeech.Gender.Female : QuestToSpeech.Gender.Male,
                        LangCode = voice.LanguageCodes[0],
                        Module   = QuestToSpeech.Module.Google
                    });
                }

                voices = list.ToArray();
            } catch (Exception ex) {
                return(string.Format("GoogleTTS Exception: {0}", ex.InnerException == null ? ex.Message : ex.InnerException.ToString()));
            }

            return(null);
        }
コード例 #13
0
        // [START tts_list_voices]
        /// <summary>
        /// Lists all the voices available for speech synthesis.
        /// </summary>
        /// <param name="desiredLanguageCode">Language code to filter on</param>
        public static int ListVoices(string desiredLanguageCode = "")
        {
            TextToSpeechClient client = TextToSpeechClient.Create();

            // Performs the list voices request
            var response = client.ListVoices(new ListVoicesRequest
            {
                LanguageCode = desiredLanguageCode
            });

            foreach (Voice voice in response.Voices)
            {
                // Display the voices's name.
                Console.WriteLine($"Name: {voice.Name}");

                // Display the supported language codes for this voice.
                foreach (var languageCode in voice.LanguageCodes)
                {
                    Console.WriteLine($"Supported language(s): {languageCode}");
                }

                // Display the SSML Voice Gender
                Console.WriteLine("SSML Voice Gender: " +
                                  (SsmlVoiceGender)voice.SsmlGender);

                // Display the natural sample rate hertz for this voice.
                Console.WriteLine("Natural Sample Rate Hertz: " +
                                  voice.NaturalSampleRateHertz);
            }
            return(0);
        }
コード例 #14
0
ファイル: KanaController.cs プロジェクト: hypermodernorg/LJSS
        public ActionResult KanaSounds()
        {
            string webRootPath   = _env.WebRootPath;
            string kanaText      = Request.Form["kanastring"];
            string kanasound     = webRootPath + "/assets/sounds/kana/" + kanaText + ".mp3";
            string kanasoundhreg = "http://localhost:5001" + "/assets/sounds/kana/" + kanaText + ".mp3";
            var    client        = TextToSpeechClient.Create();
            var    input         = new SynthesisInput
            {
                Text = kanaText
            };

            var voiceSelection = new VoiceSelectionParams
            {
                LanguageCode = "ja-JP",
                SsmlGender   = SsmlVoiceGender.Female,
                Name         = "ja-JP-Wavenet-A"
            };

            var audioConfig = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Mp3
            };

            var response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);

            if (System.IO.File.Exists(kanasound) == false)
            {
                using var output = System.IO.File.Create(kanasound);
                response.AudioContent.WriteTo(output);
            }
            return(new JsonResult(kanasoundhreg));
        }
コード例 #15
0
        public static Dictionary <string, LanguageItem> ListVoiceLanguages(Grpc.Core.Channel channel)
        {
            TextToSpeechClient client = TextToSpeechClient.Create(channel);

            Dictionary <string, LanguageItem> languages = new Dictionary <string, LanguageItem>();
            // Performs the list voices request
            var response = client.ListVoices(new ListVoicesRequest {
            });

            foreach (Voice voice in response.Voices)
            {
                foreach (var languageCode in voice.LanguageCodes)
                {
                    if (!languages.ContainsKey(languageCode.ToString()))
                    {
                        string       displayName = languageCode + " | " + new CultureInfo($"{languageCode}").DisplayName;
                        LanguageItem newItem     = new LanguageItem
                        {
                            Text = displayName,
                            Id   = languageCode
                        };

                        languages.Add(languageCode, newItem);
                    }
                }
            }
            return(languages);
        }
コード例 #16
0
        public void TextSpeech(string text)
        {
            TextToSpeechClient client = TextToSpeechClient.Create();

            SynthesisInput input = new SynthesisInput
            {
                Text = text
            };

            VoiceSelectionParams voice = new VoiceSelectionParams
            {
                LanguageCode = "ja-JP",
                SsmlGender   = SsmlVoiceGender.Female
            };

            AudioConfig config = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Linear16,
            };

            var response = client.SynthesizeSpeech(
                input,
                voice,
                config
                );

            using (var memoryStream = new MemoryStream(response.AudioContent, true))
            {
                var player = new System.Media.SoundPlayer(memoryStream);
                Console.Write("Play");
                player.Play();
            }
        }
コード例 #17
0
        /// <summary>
        /// Using environment vars, it connects to google api to generate text to speech
        /// </summary>
        /// <param name="text"></param>
        private static void synthesizeVoice(string text)
        {
            TextToSpeechClient client = TextToSpeechClient.Create();
            var response = client.SynthesizeSpeech(new SynthesizeSpeechRequest
            {
                Input = new SynthesisInput
                {
                    Text = text
                },
                // Note: voices can also be specified by name
                Voice = new VoiceSelectionParams
                {
                    LanguageCode = "en-US",
                    Name         = "en-US-Wavenet-F"
                },
                AudioConfig = new AudioConfig
                {
                    AudioEncoding   = AudioEncoding.Mp3,
                    SampleRateHertz = 32000,
                    SpeakingRate    = 1.0
                }
            });

            Debugger.Write("Successfully downloaded voice audio from google api");

            using (Stream output = File.Create($"stored_responses/{text.Replace(' ','_')}.mp3"))
            {
                response.AudioContent.WriteTo(output);
            }
        }
コード例 #18
0
        public GoogleTextToSpeechService(VoiceConfiguration voiceConfiguration)
        {
            this.voiceConfiguration = voiceConfiguration;
            client = TextToSpeechClient.Create();

            LoadAllAudioFiles();
        }
コード例 #19
0
        public async Task GenerateSpeechFile(string text, string path)
        {
            TextToSpeechClient client = TextToSpeechClient.Create();

            SynthesisInput input = new SynthesisInput
            {
                Text = text
            };

            VoiceSelectionParams voice = new VoiceSelectionParams
            {
                LanguageCode = "en-US",
                SsmlGender   = SsmlVoiceGender.Neutral
            };

            AudioConfig config = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Mp3
            };

            var response = await client.SynthesizeSpeechAsync(new SynthesizeSpeechRequest
            {
                Input       = input,
                Voice       = voice,
                AudioConfig = config
            });

            using (Stream output = File.Create(path))
            {
                response.AudioContent.WriteTo(output);
            }
        }
コード例 #20
0
        public static List <VoiceItem> ListVoices(Grpc.Core.Channel channel)
        {
            TextToSpeechClient client = TextToSpeechClient.Create(channel);

            // Performs the list voices request
            var response = client.ListVoices(new ListVoicesRequest
            {
            });

            List <VoiceItem> voices = new List <VoiceItem>();

            foreach (Voice voice in response.Voices)
            {
                foreach (var languageCode in voice.LanguageCodes)
                {
                    VoiceItem voiceItem = new VoiceItem
                    {
                        Name     = voice.Name,
                        Gender   = voice.SsmlGender.ToString(),
                        Language = languageCode,
                    };
                    voices.Add(voiceItem);
                }
            }
            return(voices);
        }
コード例 #21
0
 public GoogleCloudTextToSpeech()
 {
     //https://cloud.google.com
     //As the google api needs to get my own cred path(which I apply from google) from Environment variable. Therefore we need to add 'GOOGLE_APPLICATION_CREDENTIALS' variable to system path during the application running til it ends.
     Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Credentials", "[YOUR CREDENTIALS].json"));
     client = TextToSpeechClient.Create();
 }
コード例 #22
0
        public void GenerateSpeech(string content, string file)
        {
            var client = TextToSpeechClient.Create();
            var input  = new SynthesisInput
            {
                Text = content
            };

            // Build the voice request.
            var voiceSelection = new VoiceSelectionParams
            {
                LanguageCode = "en-US",
                SsmlGender   = SsmlVoiceGender.Female
            };

            // Specify the type of audio file.
            var audioConfig = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Linear16
            };

            // Perform the text-to-speech request.
            var response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);

            // Write the response to the output file.
            using (var output = File.Create(file))
            {
                output.Write(response.AudioContent, 0, response.AudioContent.Length);
            }
        }
コード例 #23
0
        private void TTS_Button_Click(object sender, RoutedEventArgs e)
        {
            // Instantiate a client
            TextToSpeechClient client = TextToSpeechClient.Create();

            // Set the text input to be synthesized.
            SynthesisInput input = new SynthesisInput
            {
                Text = "N Pay구매하신 상품의구매확정처리부탁드립니다.상품을 받으신 후 만족하셨다면 구매확정을 부탁드립니다."
                       + "아래 기한까지 구매확정을 하지 않으실 경우,이후 자동으로 구매가 확정될 예정입니다."
                       + "만일,구매확정기한 내 정상적으로 상품을 수령하지 못하신 경우에는 판매자문의 또는 구매확정 연장을 해주세요."
                       + "고객명 이 * 연님주문번호    2019100971174081주문일자    2019.10.09 23:13발송일자    2019.10.10자동구매확정일 2019.10.19"
                       + "결제정보총 주문금액  12,100원할인금액    0원환불정산액 / 포인트   0원 / 2,394원결제수단    신용카드"
                       + "최종결제금액  9,706원배송정보수령인 이*연연락처 010 - 5234 - ****배송지 14305경기도 광명시 금당로 11(하안동, 하안6단지고층주공아파트)"
                       + "603동****배송메모발송상품상품이미지애플 인증 고속충전 정품 1.2m 2m 아이패드 아이폰 케이블"
                       + "옵션 : 옵션선택: mfi인증 메탈릭1.2m_다크그레이주문금액    9,600원수량  1"
            };

            // Build the voice request, select the language code ("en-US"),
            // and the SSML voice gender ("neutral").
            VoiceSelectionParams voice = new VoiceSelectionParams
            {
                LanguageCode = "ko-KR",
                SsmlGender   = SsmlVoiceGender.Neutral
            };

            // Select the type of audio file you want returned.
            AudioConfig config = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Mp3
            };

            // Perform the Text-to-Speech request, passing the text input
            // with the selected voice parameters and audio file type
            var response = client.SynthesizeSpeech(new SynthesizeSpeechRequest
            {
                Input       = input,
                Voice       = voice,
                AudioConfig = config
            });

            // Write the binary AudioContent of the response to an MP3 file.
            using (Stream output = File.Create("C:\\Users\\이제연\\Desktop\\sample.mp3"))
            {
                response.AudioContent.WriteTo(output);
            }
            mciSendString("open \"" + "C:\\Users\\이제연\\Desktop\\sample.mp3" + "\" type mpegvideo alias MediaFile", null, 0, IntPtr.Zero);

            StringBuilder returnData = new StringBuilder(128);

            mciSendString("status MediaFile length", returnData, returnData.Capacity, IntPtr.Zero);
            int nMilliSecond = Convert.ToInt32(returnData.ToString());

            mciSendString("play MediaFile", null, 0, IntPtr.Zero);

            Thread thread = new Thread(() => _deleteMp3File("C:\\Users\\이제연\\Desktop\\sample.mp3", nMilliSecond));

            thread.Start();
        }
コード例 #24
0
        public TextToSpeechCloud()
        {
            var ttsCredentials = File.ReadAllText("credentials.json");

            Client = new TextToSpeechClientBuilder {
                JsonCredentials = ttsCredentials
            }.Build();
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: Chapmania/Juniper
        private static async Task DecodeAudioAsync(string text, TextToSpeechClient ttsClient, Voice voice)
        {
            var audio = await ttsClient
                        .GetDecodedAudioAsync(text, voice.ShortName)
                        .ConfigureAwait(false);

            await PlayAsync(audio)
            .ConfigureAwait(false);
        }
コード例 #26
0
    void Start()
    {
        #region Environment Variable
        if (!File.Exists(credentialsPath))
        {
            Debug.LogError("failure" + credentialsPath);
            return;
        }
        else
        {
            Debug.Log("success: " + credentialsPath);
        }
        Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credentialsPath);
        #endregion

        #region QuickStart
        // Instantiate a client
        TextToSpeechClient client = TextToSpeechClient.Create();

        // Set the text input to be synthesized.
        SynthesisInput input = new SynthesisInput
        {
            Text = "Hello, World!"
        };

        // Build the voice request, select the language code ("en-US"),
        // and the SSML voice gender ("neutral").
        VoiceSelectionParams voice = new VoiceSelectionParams
        {
            LanguageCode = "en-US",
            SsmlGender   = SsmlVoiceGender.Neutral
        };

        // Select the type of audio file you want returned.
        AudioConfig config = new AudioConfig
        {
            AudioEncoding = AudioEncoding.Mp3
        };

        // Perform the Text-to-Speech request, passing the text input
        // with the selected voice parameters and audio file type
        var response = client.SynthesizeSpeech(new SynthesizeSpeechRequest
        {
            Input       = input,
            Voice       = voice,
            AudioConfig = config
        });

        // Write the binary AudioContent of the response to an MP3 file.
        using (Stream output = File.Create(saveFile))
        {
            response.AudioContent.WriteTo(output);
            Debug.Log($"Audio content written to file " + saveFile);
        }
        #endregion
    }
コード例 #27
0
        public static string GenerateSpeech(string audioText)
        {
            /*
             * Generates audio when online;
             * Default fileName is audio text with illegal characters replaced by "_"
             * FileName can be specified to avoid long filenames
             *
             */
            if (!String.IsNullOrEmpty(audioText))
            {
                string credentialsFile = GetCredentialsFile();
                if (!String.IsNullOrEmpty(credentialsFile))
                {
                    try
                    {
                        GoogleCredential         credentials = GoogleCredential.FromFile(credentialsFile);
                        SynthesizeSpeechResponse response;
                        using (var textToSpeechClient = TextToSpeechClient.Create(credentials))
                        {
                            response = textToSpeechClient.SynthesizeSpeech(
                                new SynthesisInput()
                            {
                                Text = audioText
                            },
                                new VoiceSelectionParams()
                            {
                                LanguageCode = LanguageCode,
                                Name         = Voice,
                                SsmlGender   = Gender
                            },
                                new AudioConfig()
                            {
                                AudioEncoding   = AudioEncoding.Mp3,
                                SpeakingRate    = (float?)(0.95 * AudioMgr.SpeedRatio), // default speed set to 0.95
                                SampleRateHertz = 24000
                            }
                                );
                        }

                        string speechFile = Path.Combine(DirectoryMgr.TempDirectory, Guid.NewGuid().ToString() + ".mp3");
                        File.WriteAllBytes(speechFile, response.AudioContent);
                        return(speechFile);
                    }
                    catch (Exception e)
                    {
                        Logger.AddLogEntry(LogCategory.ERROR,
                                           String.Format("TextToSpeechMgr: Error reading Google credentials file: {0} ", e.ToString()));
                        var messageWin = new MessageWin("TextToSpeechMgr",
                                                        String.Format("Error reading Google credentials file - audio not generated."));
                        messageWin.Show();
                        return(null);
                    }
                }
            }
            return(null);
        }
コード例 #28
0
 public GoogleSpeak(Pipeline pipeline, Microsoft.Psi.Audio.WaveFormat format, string languageCode) : base(pipeline)
 {
     this.gClient          = TextToSpeechClient.Create();
     this.format           = format;
     this.TextLanguageCode = languageCode;
     if (format.Equals(Microsoft.Psi.Audio.WaveFormat.Create16kHz1Channel16BitPcm()))
     {
         this.googleAudioFormat = AudioEncoding.Linear16;
     }
 }
コード例 #29
0
        private void ListVoices(string language)
        {
            TextToSpeechClient client;

            client = TextToSpeechClient.Create();
            var response = client.ListVoices(new ListVoicesRequest
            {
                LanguageCode = language
            });
        }
コード例 #30
0
 public Program()
 {
     ttsClient = TextToSpeechClient.Create(
         new Channel(
             "texttospeech.googleapis.com:443",
             GoogleCredential
             .FromFile("TTS-Robin-19301c00354e.json")
             .CreateScoped(TextToSpeechClient.DefaultScopes)
             .ToChannelCredentials()));
 }