Answer the question
In order to leave comments, you need to log in
How to use Python in C# code?
Hello, I have a Python code that converts speech to text. (Python version 3.6)
I want to recognize this result and then execute the code in C#, since it seems to me much more convenient.
Python code:
import speech_recognition as sr
sock = socket.socket()
r = sr.Recognizer()
m = sr.Microphone()
try:
with m as source:
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
result =r.recognize_google(audio, language = "ru-RU").lower()
#передать result в C# код
except:
pass
Answer the question
In order to leave comments, you need to log in
For those who are interested, I solved the problem like this:
ProcessStartInfo startInfo = new ProcessStartInfo("python");
Process process = new Process();
string directory = @"C:\Users\User\";
string script = "Name.py";
startInfo.WorkingDirectory = directory;
startInfo.Arguments = script;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
process.StartInfo = startInfo;
process.Start();
await Task.Delay(5000);
process.Close();
Try IronPython, I think this is what you need. https://metanit.com/sharp/tutorial/9.3.php
Dump python and call google api directly. Capture audio using NAudio. However, the engine is not fundamental, you can choose Yandex, Microsoft, Amazon
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question