/// <summary> /// 下載Google語音 /// </summary> /// <param name="Text">輸入文字</param> /// <param name="languageCode">語音的語言</param> /// <returns>語音的保存位置</returns> public static string GoogleTransVoice(string Text, LanguageCode.CommonCode languageCode = LanguageCode.CommonCode.en) { string voice = @"cache\" + Text + "_tts.mp3"; if (!File.Exists(voice)) { string url = GoogleTransVoiceUrl(Text, languageCode); DownLoadFile(url, @"cache\", Text + "_tts.mp3"); } return(voice); }
/// <summary> /// 組合出Google語音請求API /// </summary> /// <param name="Text">輸入文字</param> /// <param name="languageCode">語音的語言</param> /// <returns>語音URL</returns> public static string GoogleTransVoiceUrl(string Text, LanguageCode.CommonCode languageCode = LanguageCode.CommonCode.en) { string token = GetTokenAsync(Text).GetAwaiter().GetResult(); string TTSVoice = "https://translate.google.com/translate_tts?"; TTSVoice += "&ie=UTF-8"; // 輸入編碼 TTSVoice += "&q=" + Text; // 輸入文字 TTSVoice += "&tl=" + languageCode; // 輸出語言 TTSVoice += "&total=1"; TTSVoice += "&idx=0"; TTSVoice += "&textlen=" + Text.Length; // 輸入文字長度 TTSVoice += "&tk=" + token; // 安全性驗證值 TTSVoice += "&client=webapp"; TTSVoice += "&prev=input"; //TTSVoice += "&ttsspeed = 0.24"; // 語音速度 return(TTSVoice); }