public static string WrapAmazonPitchParam(this TTSPitch pitch, string text) { int pitchShift; switch (pitch) { case TTSPitch.X_Low: case TTSPitch.Low: case TTSPitch.High: case TTSPitch.X_High: //proceed break; case TTSPitch.Medium: return(text); case TTSPitch.Unassigned: goto case TTSPitch.Medium; default: BGC.Debug.LogError($"TTS Pitch not supported {pitch}"); goto case TTSPitch.Unassigned; } //pitchShift = (int)Math.Round(100 * Math.Pow(2, pitch.GetSemitoneShift() / 12.0)) - 100; pitchShift = (int)Math.Round(100 * (pitch.GetSemitoneShift() / 12.0)); return($"<prosody pitch=\"{pitchShift:+0;-#}%\">{text}</prosody>"); }
protected async Task <string> GetGoogleSynthSpeech(string text, TTSVoice voicePreference, TTSPitch pitchPreference, string filename = null) { VoiceSelectionParams voice = voicePreference.GetGoogleVoiceSelectionParams(); AudioConfig config = new AudioConfig { AudioEncoding = AudioEncoding.Mp3, Pitch = pitchPreference.GetSemitoneShift() }; //TTS SynthesisInput input = new SynthesisInput { Ssml = PrepareGoogleSSML(text) }; // Perform the Text-to-Speech request, passing the text input // with the selected voice parameters and audio file type GoogleSynthesizeSpeechResponse response = await googleClient.SynthesizeSpeechAsync(input, voice, config); // Write the binary AudioContent of the response to file. string filepath; if (string.IsNullOrWhiteSpace(filename)) { filepath = Path.Combine(TTSFilesPath, $"{Guid.NewGuid()}.mp3"); } else { filepath = Path.Combine(TTSFilesPath, $"{filename}.mp3"); } using (Stream file = new FileStream(filepath, FileMode.Create)) { response.AudioContent.WriteTo(file); } return(filepath); }