开发者

Getting output from Python files when executed through C#

Im calling Python script from a C# app to execute with the code below

string srCommandName = "customWhisper.py D:\Tas\Monitor\Stemme_226.m4a 41f850e7-455e-4f84-b1eb-a5cccea49046.txt"
ProcessStartInfo psInfo = new ProcessStartInfo(srCommandName);
psInfo.UseShellExecute= false;
psInfo.RedirectStandardOutput = true;
using (Process process = Process.Start(psInfo))
{
    using (StreamReader reader = process.StandardOutput)
    {
        string result = reader.ReadToEnd();
        if (result=="")
        { }
    }
}

My Python code is:

try:   
  if len(sys.argv)==3:
    mediaPath = sys.argv[1] 
    textFilePath = sys.argv[2]
    model = whisper.load_model("tiny")
    isExist = os.path.exists(mediaPath)    
    if isExist:
        results = model.transcribe(media开发者_开发问答Path, language = "da")
        stab_segments = results['segments']
        text_file = open(textFilePath, "w",encoding="utf-8")
        for i in stab_segments:
           text_file.write(i["text"] + '\n')
        text_file.close()
        print(0)
    else:
        print(1)
  else:
    print(len(sys.argv))
except Exception as er:
    print(er)

The desired output from string result = reader.ReadToEnd(); should had been 0 (print 0) on success or one of the other prints. But its the srCommandName

Is there any way to get Python to return a value when called from C#

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜