View ITask.CreateView(LayoutInflater inflater, ViewGroup container) { v = inflater.Inflate(layoutId, container, false); tts = new Text2Speech(v.Context); // Create all parts from, for instance, a xml file var s = factory.GetNextGameObjects(v.Context, tts); CreateTask(v, s); return(v); }
public void PlayMp3FromUrl(string url, string text, Voice voice) { try { Text2Speech tts = new Text2Speech(FPT_TOKEN, ""); AsyncResponseData responseData = tts.Speech(text, voice); DownloadFile(responseData.async, url); } catch(Exception ex) { Console.WriteLine(ex.Message); } }
public void PlayMp3FromUrl(string url, string text, Voice voice, string mytoken) { Text2Speech tts = new Text2Speech(mytoken, url); AsyncResponseData responseData = tts.Speech(text, voice); // nhận một object chứa link của file Mp3. Console.WriteLine(responseData.audio_menv_url); WebClient wc = new WebClient(); wc.DownloadFile(responseData.audio_menv_url ?? responseData.async, responseData.request_id + ".mp3"); FileStream memoryStream = File.OpenRead(responseData.request_id + ".mp3"); try { memoryStream.Position = 0; using ( WaveStream blockAlignedStream = new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader(memoryStream)))) { using (_waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback())) { _waveOut.Init(blockAlignedStream); InnerControl(false); while (_waveOut.PlaybackState == PlaybackState.Playing) { Thread.Sleep(100); } InnerControl(); } } } catch (Exception) { // ignored } finally { InnerControl(); } }