Beispiel #1
0
        public ZmJieGuo GetShengYin(string txt)
        {
            AliTtsOption ao = new AliTtsOption();

            ao.text = txt;
            return(AliTTSHelper.txt2ShengYin(ao));
        }
    /// <summary>
    /// 文字转声音
    /// </summary>
    /// <returns>声音文件名称</returns>
    public static ZmJieGuo txt2ShengYin(AliTtsOption ao)
    {
        ZmJieGuo jg  = new ZmJieGuo();
        string   sid = getSid(ao.text);

        if (!string.IsNullOrEmpty(sid))
        {
            return(jg.Ok(sid));
        }
        ao.token = AliMain.getToken();
        string   filename = Guid.NewGuid().ToString() + ".mp3";
        string   filepath = AppHelper.AppRootDir + "//upload//" + filename;
        string   url      = "https://nls-gateway.cn-shanghai.aliyuncs.com/stream/v1/tts";
        string   jsondata = ao.ToJSON();
        ZmJieGuo jgs      = HttpHelper.post2Save(url, jsondata, filepath);

        if (jgs.isOk)
        {
            return(jg.Ok(filename));
        }
        else
        {
            return(jgs);
        }
    }
Beispiel #3
0
        private ZmJieGuo AddShengYin(string txt, string uid, string fenlei)
        {
            AliTtsOption ao = new AliTtsOption();

            ao.text = txt;
            ZmJieGuo jg = AliTTSHelper.txt2ShengYin(ao);

            if (jg.isOk)
            {
                ZmParameterList parameters = new ZmParameterList();
                parameters.AddParam("uid", uid);
                parameters.AddParam("sid", jg.data.ToString());
                parameters.AddParam("txt", ao.text);
                parameters.AddParam("fenlei", fenlei);
                int i_jg = MySqlHelper.InsertTab("fanyijilu", parameters.ParamList);
                if (i_jg != 1)
                {
                    return(jg.Error("翻译成功,插入数据库失败"));
                }
            }
            return(jg);
        }