Ich habe ein Programm in C# geschrieben und Werte von Praat (Phonetik-Software) berechnet. Ich habe bereits ein Praat-Skript mit praatcon.exe, das die Ergebnisse auf einer Windows-Konsole (cmd.exe) druckt. Kann ich dieses Ergebnis in meiner C# -Anwendung verwenden? Wie?Werte von Praat mit einem C# -Programm erhalten
Oder gibt es einen besseren Weg, um die Ergebnisse zu erhalten, z.B. mit dem Befehl "Sendsocket"? Wie benutzt man dieses?
Edit: Es funktioniert gut mit diesem Code:
ProcessStartInfo si = new ProcessStartInfo();
si.FileName = "praatcon.exe"; //name of the handle program from sysinternals
//assumes that it is in the exe directory or in your path
//environment variable
//the following three lines are required to be able to read the output (StandardOutput)
//and hide the exe window.
si.RedirectStandardOutput = true;
si.WindowStyle = ProcessWindowStyle.Hidden;
si.UseShellExecute = false;
si.Arguments = "-a example.praat filename.wav"; //you can specify whatever parameters praatcon.exe needs here; -a is mandatory!
//these 4 lines create a process object, start it, then read the output to
//a new string variable "s"
Process p = new Process();
p.StartInfo = si;
p.Start();
string s = p.StandardOutput.ReadToEnd();
Es ist sehr wichtig, die "-a" Parameter mit praatcon.exe zu verwenden. Siehe Erläuterung here.
Ich habe diesen Code in einer Windows Forms-Anwendung ausprobiert und sehe, wie sich die Konsole öffnet und für einen kurzen Moment die richtige Lösung zeigt. Aber meine Saite ist leer. Scheint als ob p.StandardOutput.ReadToEnd() nicht gut funktioniert. Vielleicht liest es die Standardausgabe eines anderen Threads aus? Was mache ich falsch? –
OK, dein Code funktioniert großartig! "Mein" Fehler war, dass ich praatcon.exe nicht mit dem Argument "-a" aufgerufen habe! –