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