Je suis presque sûr que je fais cela correctement mais je n'arrive pas à comprendre ce qui cause cette erreur ou comment la corriger. Toute aide serait appréciée. Le code est ci-dessous avec l'erreur en dessous.
Code. Je l'ai posté en entier car je ne sais pas ce qui est pertinent pour cette erreur.
public class voiceStuff
{
public WaveInEvent waveInStream;
private static StreamSpeechRecognizer _recognizer;
WaveFileWriter writer;
private MemoryStream mem;
public void record()
{
waveInStream.NumberOfBuffers = 2;
waveInStream.StartRecording();
recognize();
}
public void recognize()
{
Console.ReadKey();
waveInStream.StopRecording();
}
public voiceStuff()
{
Logger.LogReceived += Logger_LogReceived;
waveInStream = new WaveInEvent();
waveInStream.NumberOfBuffers =2;
waveInStream.WaveFormat = new WaveFormat(16000, 1);
mem = new MemoryStream();
writer = new WaveFileWriter(mem, waveInStream.WaveFormat);
waveInStream.DataAvailable += onDataAvailable;
var modelPath = Path.Combine(Directory.GetCurrentDirectory(), "model/en-us");
var dictionaryPath = Path.Combine(modelPath, "cmudict-en-us.dict");
var languageModelPath = Path.Combine(modelPath, "en-us.lm.dmp");
var configuration = new Configuration
{
AcousticModelPath = modelPath,
DictionaryPath = dictionaryPath,
LanguageModelPath = languageModelPath,
UseGrammar = true,
GrammarPath = "Models",
GrammarName = "hello"
};
_recognizer = new StreamSpeechRecognizer(configuration);
waveInStream.StartRecording();
Console.ReadKey();
waveInStream.StopRecording();
Thread.Sleep(50);
_recognizer.StartRecognition(mem, new TimeFrame(mem.Length));
SpeechResult result = _recognizer.GetResult();
_recognizer.StopRecognition();
Console.WriteLine("result: " + result?.GetHypothesis());
//syn speech
}
public void onDataAvailable(object sender, WaveInEventArgs e)
{
writer.Write(e.Buffer, 0, e.BytesRecorded);
}
static void Logger_LogReceived(object sender, LogReceivedEventArgs e)
{
Console.WriteLine(e.Message);
}
}
Erreur
9/12/2016 9:55:42 PM Error StreamSpeechRecognizer System.NullReferenceException: Object reference not set to an instance of an object.
at Syn.Speech.Linguist.Dictionary.TextDictionary.Allocate()
at Syn.Speech.Linguist.Language.Grammar.Grammar.Allocate()
at Syn.Speech.Linguist.Flat.FlatLinguist.Allocate()
at Syn.Speech.Decoders.Search.SimpleBreadthFirstSearchManager.Allocate()
at Syn.Speech.Recognizers.Recognizer.Allocate()
at Syn.Speech.Api.StreamSpeechRecognizer.StartRecognition(Stream stream, TimeFrame timeFrame)
9/12/2016 9:55:42 PM Error StreamSpeechRecognizer Syn.Speech.Helper.IllegalStateException: Expected state Ready actual state Allocating
at Syn.Speech.Recognizers.Recognizer.CheckState(State desiredState)
at Syn.Speech.Recognizers.Recognizer.Recognize(String referenceText)
at Syn.Speech.Api.AbstractSpeechRecognizer.GetResult()
9/12/2016 9:55:42 PM Error StreamSpeechRecognizer Syn.Speech.Helper.IllegalStateException: Expected state Ready actual state Allocating
at Syn.Speech.Recognizers.Recognizer.CheckState(State desiredState)
at Syn.Speech.Recognizers.Recognizer.Deallocate()
at Syn.Speech.Api.StreamSpeechRecognizer.StopRecognition()