国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

C# Web應(yīng)用調(diào)用EXE文件的一些實(shí)踐

這篇具有很好參考價值的文章主要介紹了C# Web應(yīng)用調(diào)用EXE文件的一些實(shí)踐。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

目錄

需求

范例運(yùn)行環(huán)境

可執(zhí)行文件的設(shè)計

調(diào)用可執(zhí)行文件方法

RunExecuteFile

RunShellExecuteFile

方法的區(qū)別

WEB調(diào)用舉例

小結(jié)


需求

最近同事使用Python開發(fā)了一款智能文字轉(zhuǎn)語音的程序,經(jīng)討論部署在WINDOWS環(huán)境服務(wù)器下,因此需要生成目標(biāo)為可執(zhí)行程序文件,即EXE文件。需要在WEB應(yīng)用程序里進(jìn)行調(diào)用,并傳遞相關(guān)參數(shù)。

該測試效果如下圖:

C# Web應(yīng)用調(diào)用EXE文件的一些實(shí)踐,c#,開發(fā)語言

打開AI語音合成配置如下:

?C# Web應(yīng)用調(diào)用EXE文件的一些實(shí)踐,c#,開發(fā)語言

如圖配置中,可以選擇朗讀人角色,音量大小,音調(diào)高低和控制語速選項,?此款應(yīng)用將在合成音視頻中起到關(guān)鍵作用。?

范例運(yùn)行環(huán)境

操作系統(tǒng): Windows Server 2019 DataCenter

.net版本:?.netFramework4.7.1 或以上

開發(fā)工具:VS2019 ?C#

可執(zhí)行文件的設(shè)計

可執(zhí)行文件 edgetts.exe 實(shí)現(xiàn)文字轉(zhuǎn)語音功能,其說明如下:

序號 參數(shù) 類型 說明
1 -filename 字符 存在的文件名

word docx文檔

txt文本文件

md markdown文檔

2 -s 角色 固定值 主播的角色值
3 -p 字符 固定值 音調(diào)高低
4 -r 1位小數(shù)數(shù)值 0.1開始的倍速 默認(rèn)為1.0
5 -v 整數(shù) 0到100 音量大小

調(diào)用方法:

edgetts.exe 要轉(zhuǎn)換的文件名???[-s 聲音參數(shù) -p 音調(diào)參數(shù) -r速度參數(shù) -v 音量參數(shù)]
調(diào)用舉例:

edgetts d:\tts\test.txt

edgetts d:\tts\test.txt? -s yunyang? -p default -r 1.0? -v 100

調(diào)用說明:

1、除要轉(zhuǎn)換的文件名為必要參數(shù)外,其他參數(shù)均有默認(rèn)值
2、轉(zhuǎn)換程序不要放在根目錄下
3、轉(zhuǎn)換程序在轉(zhuǎn)換文本相同路徑下生成同名的mp3文件
4、轉(zhuǎn)換程序需要連接外網(wǎng)

調(diào)用可執(zhí)行文件方法

需要引用 using System.Diagnostics;?

程序集 System.Diagnostics.Process.dll 提供對本地和遠(yuǎn)程進(jìn)程的訪問權(quán)限并能夠啟動和停止本地系統(tǒng)進(jìn)程。

包括兩種方法,方法包括需要調(diào)用的可執(zhí)行文件名和可提供的參數(shù):

RunExecuteFile

 public string RunExecuteFile(string filename,string arguments)
        {
            Process prc = new Process();
            try
            {
                prc.StartInfo.FileName = filename;
                prc.StartInfo.Arguments = arguments;
                prc.StartInfo.UseShellExecute = false;
                //輸入輸出重定向
                prc.StartInfo.RedirectStandardError = true;
                prc.StartInfo.RedirectStandardInput = true;
                prc.StartInfo.RedirectStandardOutput = true;
                prc.StartInfo.CreateNoWindow = false;
                prc.Start();
                //獲得輸出
                string output = prc.StandardOutput.ReadLine();
                return output;
            }
            catch (Exception ex)
            {
                if (!prc.HasExited)
                {
                    prc.Close();
                }
                return ex.Message.ToString();
            }
            return "";

        }

RunShellExecuteFile

?

public string RunShellExecuteFile(string filename, string arguments)
{
            System.Diagnostics.Process prc = new System.Diagnostics.Process();
            prc.StartInfo.FileName = filename;
            prc.StartInfo.Arguments = arguments;
            prc.StartInfo.UseShellExecute = true;
            prc.StartInfo.CreateNoWindow = true;
            prc.Start();
            prc.WaitForExit();
            return "";
}

方法的區(qū)別

主要區(qū)別在于?UseShellExecute 的屬性的?true 或 false 。該屬性獲取或設(shè)置指示是否使用操作系統(tǒng) shell 啟動進(jìn)程的值。

如果應(yīng)在啟動進(jìn)程時使用 shell,則為?true ;如果直接從可執(zhí)行文件創(chuàng)建進(jìn)程,則為? false 。 .NET Framework 應(yīng)用默認(rèn)值為?true?。為 true 的時候表示可以嘗試調(diào)用一切可以調(diào)用的程序,但不限于EXE文件。

WEB調(diào)用舉例

根據(jù)前面AI語音合成圖示,可編寫如下后端調(diào)用示例代碼:

protected void Button1_Click(object sender, EventArgs e)
    {
        string tts = "D:\\tts\\edgetts.exe";
        string tts_para = " -s " + x_speaker.SelectedValue;
        if (x_volume.Text != "")
        {
            tts_para += " -v " + x_volume.Text;
        }
        if (x_rate.Text != "")
        {
            tts_para += " -r " + x_rate.Text;
        }
        if (x_pitch.SelectedValue != "default")
        {
            tts_para += " -p " + x_pitch.SelectedValue;
        }
        string cdir = Request.PhysicalApplicationPath + "\\test\\ai\\";
        string[] allfs = Directory.GetFiles(cdir);
        for (int i = 0; i < allfs.Length; i++)
        {
            string mp3 = allfs[i].ToLower();
            File.Delete(mp3);
        }
        string guid = System.Guid.NewGuid().ToString().Replace("-", "");
        string txtfile = Request.PhysicalApplicationPath + "\\test\\ai\\"+guid+".txt";
        SaveToFile(txtfile,debug.Text, false, Encoding.UTF8, 512);
        string mp3file = Request.PhysicalApplicationPath + "\\test\\ai\\"+guid+".mp3";
        string rv=RunShellExecuteFile(tts, " "+txtfile + tts_para);
        if (File.Exists(mp3file))
        {
            testaudio.Style["display"] = "";
            testaudio.Attributes["src"] = "https://" + Request.Url.Host + "/bfile/ai/" + guid + ".mp3";
            string imgurl = "https://" + Request.Url.Host + "/test/ai/images/boy.jpg";
            if (x_speaker.SelectedValue == "xiaoxiao" || x_speaker.SelectedValue == "xiaoyi" || x_speaker.SelectedValue == "yunxia")
            {
                imgurl = "https://" + Request.Url.Host + "/test/ai/images/girl.jpg";
            }
            layer.options_yes = "document.getElementById('testaudio').play();layer.closeAll();";
            layer.open("<img src=\""+imgurl+"\" width=200/>語音合成成功!", "'點(diǎn)這里播放'", "ok");
        }
        else
        {
            debug.Text = rv;
            layer.open("未找到文件!" + tts+ txtfile + tts_para, "'確定'", "ok");
        }

    }

public string SaveToFile(string PathFile,string filecontent,bool append,System.Text.Encoding encodtype,int buffersize)
		{
			string rv="";
			StreamWriter df=new StreamWriter (PathFile,append,encodtype,buffersize);
			try
			{
				df.Write(filecontent);
				df.Close();
			}
			catch(Exception e)
			{
				rv=e.Message;
				df.Close();
			}
			finally
			{
				df.Close();
			}
			return rv;

		}//SaveToFile Function

前端代碼示例如下:

    <div id="h5panel" runat="server" style="margin-top:-50px" class="login-box query-panel">
<div style="text-align:left"><asp:HyperLink ID="backurl" Text="返回" onclick="layer.open({ type: 2, shadeClose: false, content: '正在返回頁面,請稍候...' });"  NavigateUrl="/cc/prods/media/msIndex.aspx"  runat="server"/> </div>
        <h2>
            <asp:Label ID="fnamelabel" runat="server" Text="文字轉(zhuǎn)語音AI合成測試"></asp:Label></h2>
        <div class="user-box" style=" color:White; text-align:center; margin-bottom:50px">
<br><br>
       <div class="user-box" style=" display:none1; padding-top:10px;">
           <div style="display:flex">
            <asp:TextBox  TextMode="MultiLine" Rows="6" ID="debug" Height="100px" Text="Hello!歡迎來到立德云!" style="color:White; width:100%; background: #fff;display:none1; background-color:Black;filter:opacity(50%);"  runat="server"></asp:TextBox>          
            </div>
      </div>
      <audio id="testaudio" runat="server" autoplay="autoplay"  style="display:none" controls>  </audio>
              <div class="user-box" style="margin-bottom:0px;display:flex;width:100%;justify-content:flex-end;">
        <input type="button" value="打開AI語音合成配置" style=" border-radius:5px" onclick="document.getElementById('ai_profile').style.display=''" />
        </div>
           <div id="ai_profile" class="user-box" style="display:none; margin-top:0px;">
        <div class="form-horizontal" style=" margin-left:20px; border-style:solid; border-width:1px; border-radius:5px; padding-left :50px;">
                        <div class="form-group" style=" margin-top:30px;">
                            <label class="col-sm-1  control-label" style="font-size:12pt; text-align:center;">
                            朗讀人角色
                            </label>
                            <div class="col-sm-2">
                                <asp:DropDownList ID="x_speaker"  checkSchema="notnull" noClear CssClass="form-control" cName="音調(diào)"  AUTOCOMPLETE="off" required="" runat="server">
                                <asp:ListItem Value="xiaoxiao">曉曉</asp:ListItem>
                                <asp:ListItem Value="xiaoyi">曉依</asp:ListItem>
                                <asp:ListItem Value="yunjian">云健</asp:ListItem>
                                <asp:ListItem Value="yunxi">云溪</asp:ListItem>
                                <asp:ListItem Value="yunxia">云霞</asp:ListItem>
                                <asp:ListItem Selected="True" Value="yunyang">云揚(yáng)</asp:ListItem>
                                </asp:DropDownList>
                            </div>
                            <label class="col-sm-1  control-label" style=" font-size:12pt; text-align:center;">
                            音量
                            </label>
                            <div class="col-sm-1">
                                <asp:TextBox ID="x_volume"  checkSchema="notnull" Text="100" noClear CssClass="form-control" cName="音量"  AUTOCOMPLETE="off" required="" runat="server">
                                </asp:TextBox>
                            </div>

                          </div>
                        <div class="form-group">
                            <label class="col-sm-1  control-label" style=" font-size:12pt; text-align:center;">
                            音調(diào)
                            </label>
                            <div class="col-sm-2">
                                <asp:DropDownList ID="x_pitch"  checkSchema="notnull" noClear CssClass="form-control" cName="音調(diào)"  AUTOCOMPLETE="off" required="" runat="server">
                                <asp:ListItem>default</asp:ListItem>
                                <asp:ListItem>x-low</asp:ListItem>
                                <asp:ListItem>low</asp:ListItem>
                                <asp:ListItem>medium</asp:ListItem>
                                <asp:ListItem>high</asp:ListItem>
                                <asp:ListItem>x-high</asp:ListItem>
                                </asp:DropDownList>
                            </div>
                            <label class="col-sm-1  control-label" style=" font-size:12pt; text-align:center;">
                            語速
                            </label>
                            <div class="col-sm-1">
                                <asp:TextBox ID="x_rate"  checkSchema="notnull" Text="1.0" noClear CssClass="form-control" cName="語速"  AUTOCOMPLETE="off" required="" runat="server">
                                </asp:TextBox>
                            </div>
                       </div>
        </div>
     </div>

       <div class="user-box" style="text-align:center; display:none1; padding-top:10px;">
        <div align="center">
        <asp:Button ID="Button1" Text="AI語音合成" OnClientClick="layer.open({ type: 2, shadeClose: false, content: '正在進(jìn)行AI語音合成...' });" 
                style="width:30%; background-color:#1E90FF;color:White;border-color:#87CEFA;padding-left:10px; padding-right:10px" 
                CssClass="form-control" runat="server" onclick="Button1_Click"  />
        </div>
       </div>

        <div class="user-box" style="text-align:center; display:none">
                <video id="coplayer" autoplay="autoplay" controls="controls" webkit-playsinline playsinline x5-playsinline x-webkit-airplay="allow" style="margin: 0px auto; width:100%" runat="server" ></video>
                <a id="b_rate" onclick="rate(this);" style=" float:right; line-height:25px; margin-right:10px; color:#fff;display:none;">1x</a> 
        </div>
        <div class="ann" >
            <label><asp:Literal ID="x_introduce" runat="server"/></label>
        </div>
        
    </div>
<script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
 <script type="text/javascript" src="hls.min.0.12.4.js"> </script>
 <script type="text/javascript" src="tcplayer.v4.min.js"> </script>
<script type="text/javascript" language="javascript" src="/master/js/jquery.js" ></script><!-- BASIC JS LIABRARY -->



</div>

小結(jié)

在實(shí)際的應(yīng)用中,調(diào)用 RunShellExecuteFile 方法更加通用一些,本示例調(diào)用 RunExecuteFile沒有成功,因協(xié)作需要,我們需要嘗試多種方法進(jìn)行解決,而不是要在第一時間要求其它團(tuán)隊更改設(shè)計。

layer彈出框的代碼請參考我的上傳資源:layer 移動版彈出層組件的改造版

調(diào)用成功后會顯示如下圖:

C# Web應(yīng)用調(diào)用EXE文件的一些實(shí)踐,c#,開發(fā)語言

C# Web應(yīng)用調(diào)用EXE文件的一些實(shí)踐,c#,開發(fā)語言?

如圖我們看到使用了 H5 的?video 控件進(jìn)行了演示播放。

再次感謝您的閱讀,歡迎討論指教!文章來源地址http://www.zghlxwxcb.cn/news/detail-844896.html

到了這里,關(guān)于C# Web應(yīng)用調(diào)用EXE文件的一些實(shí)踐的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • web瀏覽器打開本地exe應(yīng)用

    web瀏覽器打開本地exe應(yīng)用

    瀏覽器打開本地exe程序我們可以使用ActiveXObject方法,但是只支持IE,谷歌、火狐等瀏覽器并不支持此操作。 那問題來了,我們又該如何操作? 經(jīng)過本博主的不斷學(xué)習(xí)探索終于找到了一條,像百度網(wǎng)盤那樣打本地exe應(yīng)用的辦法。我們可以通過添加注冊表. 向系統(tǒng)添加一個類似于

    2024年02月13日
    瀏覽(24)
  • C#如何打包EXE程序生成setup安裝文件

    C#如何打包EXE程序生成setup安裝文件

    項目結(jié)束之后,有需要將winForm程序打包成.exe文件提供給用戶。 這里記錄一下打包過程。 1:首先獲取打包插件,如果你的VS已經(jīng)安裝,忽略此步驟。 點(diǎn)擊 工具-擴(kuò)展和更新,選擇聯(lián)機(jī),搜索installer,安裝。 Vs2010以上版本基本上都有安裝。 2:創(chuàng)建一個安裝向?qū)ы椖?創(chuàng)建過程

    2024年02月12日
    瀏覽(29)
  • c# 項目文件 打包成exe安裝包 (vs2015)

    c# 項目文件 打包成exe安裝包 (vs2015)

    1 Visual Studio 2015 必須有相關(guān)的打包組件; 2 Visual Studio的打包組件有 InstallShield 和 Visual Studio Installer Projects (安裝包:VSI_bundle)組件; 3 Visual Studio Installer Projects還可在VS軟件中下載,下載方式如下: a)點(diǎn)中菜單欄的“工具”選項,并選中“擴(kuò)展和更新”; b)在搜索框輸入

    2024年02月05日
    瀏覽(23)
  • C# 如何將使用的Dll嵌入到.exe應(yīng)用程序中?

    C# 如何將使用的Dll嵌入到.exe應(yīng)用程序中?

    有沒有想自己開發(fā)的exe保留一點(diǎn)神秘,不想讓他人知道軟件使用了哪些dll; 又或許是客戶覺得一個軟件里面的dll文件太多了,能不能簡單一點(diǎn),直接雙擊.exe就可以直接運(yùn)行了,別搞那么多亂七八糟的。無論是主動還是被動,這就產(chǎn)生了一個需求, 如何將軟件調(diào)用的dll嵌入到

    2024年02月10日
    瀏覽(18)
  • 關(guān)于使用C#調(diào)用Win32API,抓取第三方句柄,模擬鼠標(biāo)點(diǎn)擊,鍵盤發(fā)送事件(C2Prog.exe)

    關(guān)于使用C#調(diào)用Win32API,抓取第三方句柄,模擬鼠標(biāo)點(diǎn)擊,鍵盤發(fā)送事件(C2Prog.exe)

    因為最近工作需要用就把基本知識整理了一下 主要操作這個軟件寫程序和選配置 ? 下面例子和Win32以及自己封裝的庫全在工程文件里面 2023.7.10 :以前寫的代碼丟了重新寫了一下優(yōu)化了不少 ,所以特此更新一下 以前是1.7的版本目前用的是1.9版本有些不一樣需要注意 ?這里放最新

    2024年02月14日
    瀏覽(28)
  • py 打包exe應(yīng)用文件

    第一步:寫好一個py游戲或者應(yīng)用 第二步:測試能運(yùn)行后 第三步: 執(zhí)行命令 第四步: 執(zhí)行打包命令 基本使用第三個 另外兩個便于測試 參數(shù)詳情: -F, -onefile? ? ? ? ? ?單一文件部署 -D,-onedir? ? ? ? ? ? ?單一目錄部署 -tk? ???????????????????????在部署時包含

    2023年04月14日
    瀏覽(20)
  • 通用文字識別 本地OCR接口 json數(shù)據(jù) 任意語言 不限次調(diào)用 exe服務(wù)工具免搭建部署啟動即用

    通用文字識別 本地OCR接口 json數(shù)據(jù) 任意語言 不限次調(diào)用 exe服務(wù)工具免搭建部署啟動即用

    在這里插入圖片描述 樣本識別效果: 使用方法: 啟動本地OCR接口服務(wù) 圖片文件=base64編碼=轉(zhuǎn)json格式=傳到對應(yīng)接口 本地OCR程序: 文件太大沒法傳,要會員,我剛刪掉了一個復(fù)雜模型,能用上得再問我要把。微:huang582716403

    2024年02月11日
    瀏覽(33)
  • vue開發(fā)桌面exe應(yīng)用

    Electron-vue Electron-vue搭建vue全家桶+Element UI客戶端(一) 如何使用Vue.js構(gòu)建桌面應(yīng)用程序

    2024年02月10日
    瀏覽(17)
  • C#利用Costura.Fody制作綠色單文件程序(含多個Dll)合并成一個Exe)

    開發(fā)程序的時候經(jīng)常會引用一些第三方的DLL,然后編譯生成的exe文件就不能脫離這些DLL獨(dú)立運(yùn)行了。這樣交給用戶很不方便,希望的效果是直接交付一個exe文件。 這時候就需要借助一款名為Fody.Costura的插件。Fody.Costura是一個Fody框架下的插件,可通過Nuget安裝到VS工程中。安裝

    2024年02月09日
    瀏覽(21)
  • C#使用Asp.Net創(chuàng)建Web Service接口并調(diào)用

    C#使用Asp.Net創(chuàng)建Web Service接口并調(diào)用

    目錄 一.創(chuàng)建Asp.net web應(yīng)用以及Web Service服務(wù) (1).運(yùn)行環(huán)境 (2)創(chuàng)建項目 二.創(chuàng)建控制臺應(yīng)用來調(diào)用上面創(chuàng)建的Web Service 開發(fā)工具: Visual Studio 2022 Current (免費(fèi)社區(qū)版) 框架版本: .net framework4.7.2,更高的.net 5 、net6貌似沒有默認(rèn)提供帶web service的asp.net 應(yīng)用模板了。 確保VS的工作負(fù)荷有

    2024年01月18日
    瀏覽(29)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包