public static string Synthesize2(string text) { TextToSpeechService _textToSpeech = new TextToSpeechService(); _textToSpeech.SetCredential(_username, _password); var sample = _textToSpeech.Synthesize(text, Voice.ES_SOFIA, AudioType.WAV); string file = "sample_" + Guid.NewGuid() + ".wav"; string path = Path.Combine(HomeController._wwwRoot.WebRootPath, "audio", file); foreach (string f in Directory.EnumerateFiles(Path.Combine(HomeController._wwwRoot.WebRootPath, "audio"), "sample_*.wav")) { File.Delete(f); } using (var fileStream = File.Create(path)) { sample.CopyTo(fileStream); } return(path); }
public static byte[] SynthesizeToByteArray(string text) { TextToSpeechService _textToSpeech = new TextToSpeechService(); _textToSpeech.SetCredential(_username, _password); var sample = _textToSpeech.Synthesize(text, Voice.ES_SOFIA, AudioType.WAV); byte[] result = StreamExtension.ReadAllBytes(sample); return(result); }
private void Synthesize() { Console.WriteLine(string.Format("Calling Synthesize({0})...", _text)); var results = _textToSpeech.Synthesize(_text, Voice.EN_ALLISON, AudioType.WAV); if (results != null) { Console.WriteLine(string.Format("Succeeded to synthesize {0} | stream length: {1}", _text, results.Length)); } else { Console.WriteLine("Failed to synthesize."); } }