c#上的Google TTS字符串问题
本文关键字:字符串 问题 TTS Google 上的 | 更新日期: 2023-09-27 18:24:50
我正在使用谷歌文本到语音(TTS)。伙计们,你们都知道它一次只有100个字符串支持。我已经正确地实现了TTS部分,但不超过100个字符。所以,正如我所说,我会反对的。
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;
}
}
此外,请考虑我正在使用NAudio(使用NAudio.Wave;)。如何有效地修改此代码并毫无问题地播放整个字符串音频。
编辑问题:当我们使用谷歌TTS时,你知道它一次只支持100个字符串。我的问题是,如果我的字符串大于100,我将不允许通过谷歌进行TTS。因此,我确实想将字符串拆分为一组100秒,并在没有冲突的情况下播放音频。如何做到这一点?
请帮忙。
像一样更改此方法
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();
}