Link to home
Start Free TrialLog in
Avatar of jjrr007
jjrr007

asked on

Save File Automatically

I am writing a C# program that saves a wav file.  At this time, it is saving the file using a dialog box.  I would really appreciate if someone could show me how to change the code below so it will save automatically to a specified location.  

Also, the name of the file that should be used for saving is in a list box called "Recorded ID".  I have listed the code below that I am currently using.  

if (chkSaveToWavFile.Checked)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "All files (*.*)|*.*|wav files (*.wav)|*.wav";
sfd.Title = "Save to a wave file";
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);
Voice.AudioOutputStream = SpFileStream;
Voice.Speak(txtSpeakText.Text, SpFlags);
Voice.WaitUntilDone(Timeout.Infinite);
SpFileStream.Close();
}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ZachSmith
ZachSmith
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jjrr007
jjrr007

ASKER

Thanks.  I think this is close.  I'm not sure if this is how you intended me to use the code.  When I replaced the code snippet I have in my question with the code I attached below, I received only one error:

Error      2      The name 'SpFileMode' does not exist in the current context

When I change the word SpFileMode to capital letters- SPFILEMODE (by selecting it from the drop down context helper), I only get the error:

Error      2      'SpeechLib.SPFILEMODE' is a 'type' but is used like a 'variable'

What do you suggest?  Thanks again!

if (chkSaveToWavFile.Checked)
{
string pathToSaveTo = @"C:\my.wav";
{
SpFileStream SpFileStream = new SpFileStream();
SpFileStream.Open(pathToSaveTo, SpFileMode, false);
Voice.AudioOutputStream = SpFileStream;
Voice.Speak(txtSpeakText.Text, SpFlags);
Voice.WaitUntilDone(Timeout.Infinite);
SpFileStream.Close();
}
}

Open in new window

Looks like you're missing this line before you instantiate the SpFileStream object:
SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;

Open in new window

Avatar of jjrr007

ASKER

You are very good at this.  I'm impressed with the speed that you did that.  Please feel free to another question that I asked at:

https://www.experts-exchange.com/questions/23221787/Run-Query-In-C.html
Avatar of jjrr007

ASKER

Thank you