예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Ssml ssml = new Ssml();

            ssml.StartVoice("nozomi");
            ssml.AppendText(textBox1.Text);
            ssml.EndVoice();
            byte[] result   = TextToSpeechClient.SendRequest(ssml);
            string fileName = GetSaveFileName();
        }
예제 #2
0
파일: Form1.cs 프로젝트: khabilepravin/hack
        private void button1_Click(object sender, EventArgs e)
        {
            TextToSpeechClient client = TextToSpeechClient.Create();

            // Set the text input to be synthesized.
            SynthesisInput input = new SynthesisInput
            {
                Text = "Just putting something which makes nosense to read stuff"
            };

            // 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("sample.mp3"))
            {
                response.AudioContent.WriteTo(output);
                Console.WriteLine($"Audio content written to file 'sample.mp3'");
            }
        }
예제 #3
0
        public async Task <byte[]> TranslateTextToWav(string text)
        {
            // Instantiate a client
            var client = TextToSpeechClient.Create();

            // Set the text input to be synthesized.
            var input = new SynthesisInput
            {
                Text = text
            };

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

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

            // 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
            });

            var memStream = new System.IO.MemoryStream();

            response.AudioContent.WriteTo(memStream);
            return(memStream.ToArray());
        }