In the file are not the same data, why?

The file gets not what we need, not what we need "System.Collections.Generic.List`1[System.String]" and that's it. The file should display the text that I recorded from the microphone, recording library NAudio.
Here is the code of the speech Recognizer:
class ReadFromAFile : INotifyPropertyChanged
{
 SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(new CultureInfo("en-US"));
 Grammar dictation = new DictationGrammar();
 List<string> text = new List<string>();

 public ReadFromAFile()
{
 dictation.Name = "Dictation Grammar";
recognizer.LoadGrammar(dictation);
 recognizer.SetInputToAudioStream(File.OpenRead(@"Ex_voice.wav"), new SpeechAudioFormatInfo(44100, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
 recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognizedHandler);
 recognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(RecognizeCompletedHandler);
}

 public void WritingToTextFile()
{
 using (StreamWriter sw = new StreamWriter("Text.txt", false, System.Text.Encoding.Default))
{
sw.WriteLine(text);
sw.Close();
}
}

 public List<string> ReadingFromTextFile()
{
 List<string> temp = new List<string>();
 using (StreamReader sr = new StreamReader("Text.txt"))
{
temp.Add(sr.ReadToEnd());
}
 return temp;
}

 private void SpeechRecognizedHandler(object sender, SpeechRecognizedEventArgs e)
{
 if (e.Result != null && e.Result.Text != null)
{
text.Add(e.Result.Text);
}
else
{
 MessageBox.Show("File is empty");
}
}

 private void RecognizeCompletedHandler(object sender, RecognizeCompletedEventArgs e)
{
 if (e.Error != null)
{
 MessageBox.Show(" Error encountered " + 
 e.Error.GetType().Name + "" + e.Error.Message);
}
 if (e.Cancelled)
{
 MessageBox.Show(" Operation cancelled.");
}
 if (e.InputStreamEnded)
{
 MessageBox.Show(" End of stream encountered.");
}
}

 public event PropertyChangedEventHandler PropertyChanged;
 public void OnPropertyChanged([CallerMemberName]string prop = "")
{
 if (PropertyChanged != null)
 PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
 }

Tell me what the problem is, the thought is there, but very scary.
PS. I use MVVM, you can still are there any sticks in the wheels.
April 19th 20 at 12:10
3 answers
April 19th 20 at 12:12
Try to replace
sw.WriteLine(text);
on
sw.WriteLine(string.join(Environment.NewLine, text));
Replaced, the file is now empty. Maybe it's in the implementation of voice recording but the file that is recorded and the sound it has - Sammy_Lesch commented on April 19th 20 at 12:15
@Sammy_Lesch, before writing to a file, check how many items is in the list - kendall36 commented on April 19th 20 at 12:18
@kendall36, It didn't help, I think these line
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognizedHandler);
recognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs(RecognizeCompletedHandler);

However, this method SpeechRecognizedHandlerI prescribed an ordinary MessageBox, but he didn't show up - Sammy_Lesch commented on April 19th 20 at 12:21
@Sammy_LeschHow many items in the text before writing to file? If there is 0, nothing will recognize and list adds nothing - kendall36 commented on April 19th 20 at 12:24
@Sammy_LeschYou @kendall36 correctly says. Field textYou type is List<string>, but the method WriteLine
has no overloads for the parameter list, so he's on the field text does ToString(), try in the console to a variable of typeList<string> apply the ToString() and you will see that it will be a line "System.Collections.Generic.List`1[System.String]" .
The fact that after the string.join You the file is empty, it means that the text is nothing, i.e. it has either length 0 or all values are empty. From here a conclusion, You need to understand why text is blank. - Modesta.Kunde commented on April 19th 20 at 12:27
@Modesta.Kunde, well, I understood what was going on, thank you) - Sammy_Lesch commented on April 19th 20 at 12:30
April 19th 20 at 12:14
// and generally a bad idea to name a list of word text better 
List<string> text = new List<string>();
private readonly List<string> _translatedTextLines = new List<string>();
var output = string.Join("\n",text);
@karson_Kshlerin84, It didn't help, I think that's the case in these lines:
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognizedHandler);
recognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs(RecognizeCompletedHandler);

However, this method SpeechRecognizedHandler I prescribed an ordinary MessageBox, but he didn't show up - Sammy_Lesch commented on April 19th 20 at 12:17
April 19th 20 at 12:16
do replacements in the code:
WritingToTextFile

public void WritingToTextFile()
{
 using (StreamWriter sw = new StreamWriter("Text.txt", false, System.Text.Encoding.Default))
{
sw.WriteLine(text);
sw.Close();
}
}
on
File.WriteAllText("Text.txt", text)
ReadingFromTextFile

public List<string> ReadingFromTextFile()
{
 List<string> temp = new List<string>();
 using (StreamReader sr = new StreamReader("Text.txt"))
{
temp.Add(sr.ReadToEnd());
}
 return temp;
}
and here it is necessary to think! on
File.ReadAllText("Text.txt")if a single string orFile.ReadAllLines("Text.txt")if you need an array of strings

but it is the entry to remove that garbage code
you did not provide code that actually performs the recording/voice recognition, and that is next. all you have shown is foreplay preparation.. where is the process? (upd the one that returns empty text, or you lose him on the way to maintain)
@Maurine.Hami, to make changes only to bring the code in "clean" ? And that means "process", in the sense in which sense, everything happens in the constructor function SpeechRecognizedHandler - Sammy_Lesch commented on April 19th 20 at 12:19
@Sammy_Lesch, come when you will understand - Maurine.Hami commented on April 19th 20 at 12:22
@Maurine.Hami, so I came on Habr , to get answers, not new questions - Sammy_Lesch commented on April 19th 20 at 12:25
@Sammy_Lesch, https://www.youtube.com/watch?v=RN0-QHZnvKk - Maurine.Hami commented on April 19th 20 at 12:28
@Maurine.Hami, hahaha, very funny - Sammy_Lesch commented on April 19th 20 at 12:31

Find more questions by tags C#Speech recognition