15

How to actually speak silence for X # of milliseconds and not by using Thread.Sleep(). I'm trying to use the .Speak() function in the SpeechLib library of an SpVoice variable to speak a specific duration of silence according to a specified number of milliseconds. Particularly, in the output of a .wav file wherein I am inserting periods of silence between spoken lines of text. Using Thread.Sleep() will take an obscene amount of time to either speak or save, as I am planning to save nearly 5000 lines of spoken text to .wav with pauses in between the lines.

This is the solution I have so far:

        int pauseA = (int)(22050.0 * ((double)pauseTargetToSource.Value / 1000.0) * 2.0);
        int pauseB = (int)(22050.0 * ((double)pauseLineBreak.Value / 1000.0) * 2.0);
        while (
            (lineSource = srSource.ReadLine()) != null &&
            (lineTarget = srTarget.ReadLine()) != null)
        {
            voiceSource.Speak(lineSource, SpeechVoiceSpeakFlags.SVSFlagsAsync);
            voiceSource.WaitUntilDone(Timeout.Infinite);
            voiceSource.AudioOutputStream.Write(new byte[pauseA]);
            voiceTarget.Speak(lineTarget, SpeechVoiceSpeakFlags.SVSFlagsAsync);
            voiceTarget.WaitUntilDone(Timeout.Infinite);
            voiceSource.AudioOutputStream.Write(new byte[pauseB]);
        }

Where 22050.0 is the sample rate and pauseLineBreak.Value is the # of milliseconds. The multiplier 2.0 is for the 2-byte length of a short in the .wav data.

AudioOutputStream.Write simply writes the correct # of 00's to the file for silence.

1
  • 1
    What is the problem writing 0's?
    – user180326
    Dec 3, 2011 at 20:11

2 Answers 2

1

This is not an ideal solution but...

You could use a certain number of "silence" phoneme, i.e. '_' (underscored) (see http://msdn.microsoft.com/en-us/library/ms717239(v=vs.85).aspx) after checking how many ms it lasts. You may have to adjust the number of number of silences depending on the Rate that you set.

0

A couple options:

  • You could spin up another thread to do the operation
  • You could simply figure out how many bytes it takes per second and write them to out output stream.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.