Exemplo n.º 1
0
        private static async Task SpeakGoogle(ISpeaker speaker, string textToSpeech, string user)
        {
            textToSpeech = textToSpeech.Replace("\"", "\"\"");

            // Instantiate a client
            TextToSpeechClient client = TextToSpeechClient.Create();

            // Set the text input to be synthesized.
            SynthesisInput input = new SynthesisInput
            {
            //Text = textToSpeech,
                Ssml = File.ReadAllText("Speakers/SSML.xml").Replace("{text}", textToSpeech).Replace("{voice}", speaker.Voice).Replace("{posmsg}", speaker.Diction).Replace("{alert}", speaker.Alert),
            };

            // Build the voice request, select the language code ("en-US"),
            // and the SSML voice gender ("neutral").
            VoiceSelectionParams voice = new VoiceSelectionParams
            {
                LanguageCode = speaker.Accent.ToString(),
                //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 = await client.SynthesizeSpeechAsync(new SynthesizeSpeechRequest
            {
                Input = input,
                Voice = voice,
                AudioConfig = config
            });

            // create a temp file with .ps1 extension  
            var cFile = System.IO.Path.GetTempPath() + Guid.NewGuid() + ".mp3";

            // Write the binary AudioContent of the response to an MP3 file.
            using (Stream output = File.Create(cFile))
                response.AudioContent.WriteTo(output);

            Sounds.RandomTrollSound();

            SpeakerCore.PreSpeech(user);

            SpeakerCore.ExecuteMP3File(cFile);

            await AutomaticTranslator.Translate(textToSpeech);

        }
Exemplo n.º 2
0
        private static async Task SpeakAzure(ISpeaker speaker, string textToSpeech, string user)
        {
            textToSpeech = textToSpeech.Replace("\"", "\"\"");

            config.SpeechSynthesisVoiceName = speaker.Voice;
            using var synthesizer           = new SpeechSynthesizer(config);

            var ssml = File.ReadAllText("Speakers/SSML.xml").Replace("{text}", textToSpeech).Replace("{voice}", speaker.Voice).Replace("{posmsg}", speaker.Diction).Replace("{alert}", speaker.Alert);

            SpeakerCore.PreSpeech(user);

            var result = await synthesizer.SpeakSsmlAsync(ssml);

            await AutomaticTranslator.Translate(textToSpeech);
        }
Exemplo n.º 3
0
        public static async Task Speak(string textToSpeech, string user, bool wait = true, string speakRate = "0")
        {
            if (!await CheckStatus())
            {
                return;
            }

            Sounds.RandomTrollSound();

            PreSpeech(user);

            textToSpeech = textToSpeech.Replace("\"", "\"\"");

            // Command to execute PS
            ExecutePowerShell($@"Add-Type -AssemblyName System.speech;  
            $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer;
            $speak.Rate = {speakRate};
            $speak.Speak(""{textToSpeech}"");"); // Embedd text

            await AutomaticTranslator.Translate(textToSpeech);
        }