/// <summary> /// 构造函数,初始化引擎。 /// </summary> /// <param name="config">配置。</param> public TextToSpeechEngine(TtsConfig config) { this.Speed = SpeechSpeedEnums.medium; this.Volume = SpeechVolumeEnums.x_loud; this.BitsPerSample = 16; this.SampleRate = 16000; this.Channels = 1; TTSInterop.Init(config); }
/// <summary> /// QISRInit应当在应用程序初始化时仅调用一次。 /// </summary> /// <param name="config"></param> public static void Init(TtsConfig config) { MspErrors result = QTTSInit(config.ToString()); switch (result) { case MspErrors.MSP_SUCCESS: //成功 break; case MspErrors.MSP_ERROR_CONFIG_INITIALIZE: throw new Exception("初始化TTS的config实例时出现错误。"); default: throw new Exception("QTTS初始化失败,错误代码: " + result); } }
public TtsForm() { InitializeComponent(); player = new WavePlayer(); player.ProgressChanged += player_ProgressChanged; this.config = new TtsConfig(); config.ServerUrl = "dev.voicecloud.cn"; config.ApplicationId = "518fcbd0"; config.Timeout = 10000; config.MaxTextSize = 4096; tts = new TextToSpeechEngine(this.config); tts.AudioReceived += tts_AudioReceived; tts.ProgressChanged += tts_ProgressChanged; btnSpeakText.Click += btnSpeakText_Click; btnSpeakFormatText.Click += btnSpeakFormatText_Click; }