C#语音SDKSDK接口开发经验及具体开发实现

来源:互联网 发布:汇编语言vb和c语言区别 编辑:程序博客网 时间:2024/06/05 03:16

一、配置文件app.config

<?xml version="1.0" encoding="utf-8" ?><configuration>    <configSections>        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >            <section name="Audio.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />        </sectionGroup>    </configSections>    <applicationSettings>        <Audio.Properties.Settings>            <setting name="Audio_Audio_WebService" serializeAs="String">                <value>http://sdk3.entinfo.cn:8060/webservice.asmx</value>            </setting>        </Audio.Properties.Settings>    </applicationSettings></configuration>


 

二、群发语音(语音合成)mdAudioSend

 

参数名称

说明

类型

是否必须   

备注

Sn

软件序列号

String

格式XXX-XXX-XXX-XXXXX

Pwd

密码

String

md5(sn+password) 32位大写密文

title
主题
String

长度最大40字符

Mobile

手机号

String

手机号码多个以英文逗号隔开

txt

文本内容

String

普通文本内容,最大300个字符

Content

Wav base64串

String

文件内容,base64编码(完整文件名(包括后缀),文件base64编码串);文件名最大20个字符包括后缀,编码文件大小最大500k.如您好.wav,base64编码串

Srcnumber

源号码(号码显示)

String

源号码(号码显示)

stime

定时时间

String

格式为 yyyy-mm-dd HH:MM:SS,例如:2010-12-29 16:27:03(非定时置空)

返回rrid:201012300908160937  (示例)

输出结果:

XML格式:

1.注意事项:

  1. (1)txt 和content 不能同时为空 并且不能同时不为空.
  2. (2)语音合成请求(附加功能):

txt不为空,同时mobile为空.调用成功返回如201012300908160937那么通过下面的地址可以得到该文本合成的语音文件: http://sdk3.entinfo.cn:8060/yuyin/syn/201012300908160937_47512.wav

地址格式是:http:// sdk3.entinfo.cn:8060/yuyin/syn/rrid_特服号.wav

此处的rrid 为接口提交成功的返回值.特服号是该序列号(sn)对应的一个短号码,可以通过此接口的GetCode 方法进行获取.GetCode的返回值形式如 047512 此处0表示成功 47512 表示该sn对应的该特服号.

2.具体函数C#实现:

(1)实现语音发送功能

(2)实现语音合成功能

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using System.Web.Security;namespace Audio{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        Audio.WebService audio = new global::Audio.Audio.WebService();        //序列号密码        static string sn = "SDK-SSD-010-XXXXX";        static string password = "XXXXXX";        //这里的密码是序列号和密码的MD5码        string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(sn + password, "md5");        private void selectFile_Click(object sender, EventArgs e)        {            OpenFileDialog ofd = new OpenFileDialog();            ofd.Filter = "wav语音文件|*.wav";            ofd.Multiselect = true;            ofd.ShowDialog();            if (ofd.FileName != "")            {                txt_filename.Text = ofd.FileName;            }        }        private void btn_send_Click(object sender, EventArgs e)        {            Boolean flag = true;            if(richTextBox1.Text.Trim().Equals("")&&(txt_filename.Text.Trim().Equals("")))            {                MessageBox.Show("文本和语音文件不能同时为空");                flag = false;            }            if (richTextBox1.Text.Trim()!="" && (txt_filename.Text.Trim()!=""))            {                MessageBox.Show("文本和语音文件不能同时不为空");                flag = false;            }            if(flag)            {                string content = "";//语音文件base64编码                string txtcontent = "";//文本内容                 string title = "C#_demo 语音测试";//语音主题                 string mobile = "18636924700";//语音号码 多个以英文的逗号隔开                 string scrnumber = "";//原号码 备用                 string stime = "";//定时时间                 string result = "";                if (txt_filename.Text.Trim() != "")                {                    //读取文件流                    FileStream fs = new FileStream(txt_filename.Text, FileMode.Open);                    byte[] sendbyte = new byte[fs.Length];                    fs.Read(sendbyte, 0, sendbyte.Length);                    fs.Close();                    content = Convert.ToBase64String(sendbyte);                    txtcontent = "";                }else                {                    txtcontent =richTextBox1.Text;                    content = "";                }               result=audio.mdAudioSend(sn, pwd, title, mobile, txtcontent, content, scrnumber, stime);               if (result.StartsWith("-"))               {                   MessageBox.Show("发送失败 错误码:" + result + " 请查看文档的返回值说明");               }               else               {                   MessageBox.Show("发送成功 " + result);               }            }        }        private void button1_Click(object sender, EventArgs e)        {            string result = "";            if (!txt_filename.Text.Equals(""))            {                MessageBox.Show("合成语音文件只是针对文本合成");            }else            {                result = audio.mdAudioSend(sn, pwd, "您好","",richTextBox1.Text,"", "", "");                if (result.StartsWith("-"))                {                    MessageBox.Show("合成失败 错误码:" + result + " 请查看文档的返回值说明");                }                else                {                    MessageBox.Show("合成成功下载地址为: http://sdk3.entinfo.cn:8060/yuyin/syn/" + result + "_特服号.wav  此处的特服号需要调用GetCode方法进行获取");                }            }        }    }}


 

三、webservice返回集合对照表:

 

返回值

返回值说明

-2

帐号/密码不正确

-4

余额不足

-5

数据格式错误

-6

参数有误

-8

流量控制错误

-10

内容长度长

-11

数据库错误

-12

序列号状态错误

-13

没有提交增值内容

-14

服务器写文件失败

-15

文件内容base64编码错误

四、附加说明:

1.语音SDK地址:

常用接口地址:http://sdk3.entinfo.cn:8060/webservice.asmx

2.其它说明:

(1)开发使用的帐号必须为SDK开头,如SDK-SSD-010-00001,帐号第一次需要调用Register方法注册一次.仅需注册一次即可,信息必须真实

(2)UnRegister与Register配合使用, 连续使用不得超过10次/天;

3. 郑重声明:

(1)禁止相同的内容多个手机号连续一条一条提交. 否则禁用帐号,由此带来损失由客户自行负责.

(2)请客户提供外网服务器IP以便于绑定IP发送,提高账号的安全性!

(3)在程序里最好有配置文件,程序自动判断当某个接口连接超时提交速度变慢时.程序可以自动切换其它的接口以下是推荐的几个服务器,仅接口地址不同而已.方法全部相同;

地址1:http://sdk3.entinfo.cn:8060/webservice.asmx

这些地址都是标准的webservice地址,C#,Java客户可以按照自己熟悉的方式去解析String   

或者

地址1:http://sdk3.entinfo.cn:8060/webservice.asmx?wsdl

五、示例Demo源代码下载:

DEMO     SDK语音接口文档   所有下载

 

0 0
原创粉丝点击