2013-07-24 22 views
0

我正在使用谷歌文本到語音(TTS)。你們都知道,每次只有100個字符串支持。我已經正確實施了TTS部分,但不超過100個字符。正如我所說,我會得到例外。谷歌TTS字符串問題在c#

public void Read(string text) // Lets say text has length 250 (>100) 
    { 
     DeleteFile(); 
     ReadText(text); 
     PlaySound(); 
    } 

我必須處理音頻的方法:

public void DisposeWave() 
    { 
     if (output != null) 
     { 
      if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) output.Stop(); 
      output.Dispose(); 
      output = null; 
     } 
     if (stream != null) 
     { 
      stream.Dispose(); 
      stream = null; 
     } 
    } 

也請考慮我使用n音訊(使用NAudio.Wave)。 如何有效修改此代碼並播放整個字符串音頻沒有問題。

編輯問題: 當我們使用谷歌TTS時,你知道它只支持一次只能有100個字符串。我的問題是如果我的字符串大於100我不會允許谷歌做TTS。所以我確實想將字符串拆分成100個一組,並且沒有衝突地播放音頻。怎麼做?

請幫忙。

+0

你有很多的選擇,打破字符串'text'到不到100塊,添加一個嘗試捕捉,如果提醒它的時間越長,用戶等語句 – ToastyMallows

回答

0

改變這種方法就像

public void Read(string text) // Lets say text has length 250 (>100) 
    { 
     DeleteFile(); 

     int startIndex = 0; 
     string textToPlay = text; 
     string remainingText = text; 
     while (remainingText.Length > 100) 
     { 
      textToPlay = remainingText.Substring(startIndex, 100); 

      startIndex = startIndex + 100; 
      remainingText = text.Substring(startIndex); 
      ReadText(textToPlay); 
     } 
     ReadText(remainingText); 
     PlaySound(); 
    } 
+0

是的,這將分裂的字符串,並忽略休息,但我想播放整個字符串:( –

+0

將播放部分爲你做? – Ehsan

+0

是的我想要播放整個字符串,即使它有1000的長度 –