1
  1. Есть готовая нейросеть на python, которая позволяет создать синтез речи
  2. Мне нужно сделать приложение WinForms с полем ввода текста и кнопкой для воспроизведения этого текста.

Как мне соединить c# и нейросеть на python?

2
  • Если вы используете какую-то определенную открытую puthon обработку, то скажите какую именно. Если у вас своя, то наверное текстовое апи, какое-нибудь можно сделать. 10 мар 2020 в 11:11
  • Использую нейросеть Deep Convolutional Text-To-Speech (DCTTS)
    – Soft
    10 мар 2020 в 12:00

1 ответ 1

0

Вы можете подключится к процессу и передавать аргументами ваши параметры.

public string run_cmd(string cmd, string args)
    {
        ProcessStartInfo start = new ProcessStartInfo();
        start.FileName = "PATH_TO_PYTHON_EXE";
        start.Arguments = string.Format("\"{0}\" \"{1}\"", cmd, args);
        start.UseShellExecute = false;// Do not use OS shell
        start.CreateNoWindow = true; // We don't need new window
        start.RedirectStandardOutput = true;// Any output, generated by application will be redirected back
        start.RedirectStandardError = true; // Any error in standard output will be redirected back (for example exceptions)
        using (Process process = Process.Start(start))
        {
            using (StreamReader reader = process.StandardOutput)
            {
                string stderr = process.StandardError.ReadToEnd(); // Here are the exceptions from our Python script
                string result = reader.ReadToEnd(); // Here is the result of StdOut(for example: print "test")
                return result;
            }
        }
    }

А так же вызвать скрипты.

public string PatchParameter(string parameter, int serviceid)
    {
        var engine = Python.CreateEngine(); // Extract Python language engine from their grasp
        var scope = engine.CreateScope(); // Introduce Python namespace (scope)
        var d = new Dictionary<string, object>
        {
            { "serviceid", serviceid},
            { "parameter", parameter}
        }; // Add some sample parameters. Notice that there is no need in specifically setting the object type, interpreter will do that part for us in the script properly with high probability

        scope.SetVariable("params", d); // This will be the name of the dictionary in python script, initialized with previously created .NET Dictionary
        ScriptSource source = engine.CreateScriptSourceFromFile("PATH_TO_PYTHON_SCRIPT_FILE"); // Load the script
        object result = source.Execute(scope); 
        parameter = scope.GetVariable<string>("parameter"); // To get the finally set variable 'parameter' from the python script
        return parameter;
    }

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.