Wednesday, June 2, 2010

SAPI Save to WAVE file C#



SAPI is Microsoft's Speech SDK. It's used for either Recognition or Text To Speech Dictation TTS. This simple program saves the dictation text box to a WAV File.


private void SavetoWave(string x)
        {
            SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice speech = new SpVoice();


            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "All files (*.*)|*.*|wav files (*.wav)|*.wav";
            sfd.Title = "Save to a wave file";
            sfd.InitialDirectory = path1;
            //sfd.InitialDirectory = folderBrowserDialog1.SelectedPath;
            sfd.FilterIndex = 2;
            sfd.RestoreDirectory = true;


            if (sfd.ShowDialog() == DialogResult.OK)
            {
                SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
                SpFileStream SpFileStream = new SpFileStream();
                SpFileStream.Open(sfd.FileName, SpFileMode, false);
                speech.AudioOutputStream = SpFileStream;
                speech.Speak(x, SpFlags);
                speech.WaitUntilDone(System.Threading.Timeout.Infinite);
                SpFileStream.Close();
            }
            
            ntyEP.ShowBalloonTip(
               5000,
               AppTitle,
               "Now Saved: " + x + " as " + sfd.FileName.ToString(),
               ToolTipIcon.Info);
        }

No comments:

Post a Comment

Generating "Always On Top" NSWindow in macOS across all detected displays

Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift  Langues, you m...