Question

I'm trying to create a program that uses voice recogniton and makes a WAV file from the recognized voice, I used this code :

Recognizer.SetInputToWaveFile(@"C:\\Program Files\\MyProgram\\Bin\\STWAV\\Speech.wav");

but I'm getting this exception every time I start the voice recognition,

"Could not locate file C:\Program Files\MyProgram\Bin\STWAV\Speech.wav".

I think that my program don't have a permission to create the WAV file in this path.

Thanks for helping.

Was it helpful?

Solution

When writing to

C:\Program Files\

you will need administrator-permission. Try to write the file the user's documents or a similar place.
Using System.Environment.SpecialFolder you can get the user's documents-folder easily.

string docs = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
docs += "\\Speech.wav";
Recognizer.SetInputToWaveFile(docs);

Alternatively, but a bad idea, would be to require the user to start the program as administrator.


EDIT

The method

Recognizer.SetInputToWaveFile

is meant to READ from a file. You cannot use it to store anything in a wav-file.

Here you find a tutorial on how to record speech in .NET.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top