0

I am using google text to speech (TTS). Guys you all know it has only 100 character string support at a time. I have implemented TTS part correctly but not for greater than 100 characters. So as I said I'll get exception.

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

I have a method to dispose audio:

    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;
        }
    }

Also please consider i am using NAudio (using NAudio.Wave;). How can I modify this code efficiently and play entire string audio without problem.

Edited Question: When we use Google TTS you know there it will support 100 character string only at a single time. My problem is if my string is greater than 100 I will not allow to do TTS by google. So that I do want to split string into set of 100s and play the audio without conflict. How to do that?

Please help.

  • You have a lot of options, break the string `text` into chunks of less than 100, add a try catch, if statement that alerts the user it's longer, etc. – ToastyMallows Jul 24 '13 at 17:02

1 Answers1

0

change this method like

  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();
    }
Ehsan
  • 31,833
  • 6
  • 56
  • 65