最近一直在忙项目,都没有时间和大家分享文章了。今天是来送福利的,送个大家一个语音合成音频工具,当然这也是用Unity制作的。看到讯飞官网有个配音制作,还需要收费,我就不能忍啊,就把之前之前做的批量配音制作工具分享给大家。

就一段音频收这么贵,啧啧啧!!!
MSCDLL.cs 接口
using System;
using System.Runtime.InteropServices;
namespace msc
{
public class MSCDLL
{
#region 登录登出
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int MSPLogin(string usr, string pwd, string parameters);
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int MSPLogout();
#endregion
#region 语音识别
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr QISRSessionBegin(string grammarList, string _params, ref int errorCode);
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int QISRAudioWrite(IntPtr sessionID, byte[] waveData, uint waveLen, AudioStatus audioStatus, ref EpStatus epStatus, ref RecogStatus recogStatus);
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr QISRGetResult(IntPtr sessionID, ref RecogStatus rsltStatus, int waitTime, ref int errorCode);
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int QISRSessionEnd(IntPtr sessionID, string hints);
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int QISRBuildGrammar(IntPtr grammarType, string grammarContent, uint grammarLength, string _params, GrammarCallBack callback, IntPtr userData);
[System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)]
public delegate int GrammarCallBack(int errorCode, string info, object udata);
[DllImport("msc.dll", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr QISRUploadData(string sessionID, string dataName, byte[] userData, uint lenght, string paramValue, ref int errorCode);
#endregion
#region 语音唤醒
//定义回调函数
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int ivw_ntf_handler(string sessionID, int msg, int param1, int param2, IntPtr info, IntPtr userData);
//调用 QIVWSessionBegin(...)开始一次语音唤醒
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr QIVWSessionBegin(string grammarList, string _params, ref int errorCode);
//调用 QIVWAudioWrite(...) 分块写入音频数据
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int QIVWAudioWrite(string sessionID, byte[] waveData, uint waveLen, AudioStatus audioStatus);
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int QIVWGetResInfo(string resPath, string resInfo, uint infoLen, string _params);
//调用 QIVWRegisterNotify(...) 注册回调函数到msc。
//如果唤醒成功,msc 调用回调函数通知唤醒成功息同时给出相应唤醒数据。如果出错,msc 调用回调函数给出错误信息
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int QIVWRegisterNotify(string sessionID, [MarshalAs(UnmanagedType.FunctionPtr)]ivw_ntf_handler msgProcCb, IntPtr userData);
//调用 QIVWSessionEnd(...) 主动结束本次唤醒
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int QIVWSessionEnd(string sessionID, string hints);
#endregion
#region 语音合成
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr QTTSSessionBegin(string _params, ref int errorCode);
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int QTTSTextPut(IntPtr sessionID, string textString, uint textLen, string _params);
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr QTTSAudioGet(IntPtr sessionID, ref uint audioLen, ref SynthStatus synthStatus, ref int errorCode);
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr QTTSAudioInfo(IntPtr sessionID);
[DllImport("msc_x64", CallingConvention = CallingConvention.StdCall)]
public static extern int QTTSSessionEnd(IntPtr sessionID, string hints);
#endregion
}
public enum Errors
{
MSP_SUCCESS = 0,
MSP_ERROR_FAIL = -1,
MSP_ERROR_EXCEPTION = -2,
/* General errors 10100(0x2774) */
MSP_ERROR_GENERAL = 10100, /* 0x2774 */
MSP_ERROR_OUT_OF_MEMORY = 10101, /* 0x2775 */
MSP_ERROR_FILE_NOT_FOUND = 10102, /* 0x2776 */
MSP_ERROR_NOT_SUPPORT = 10103, /* 0x2777 */
MSP_ERROR_NOT_IMPLEMENT = 10104, /* 0x2778 */
MSP_ERROR_ACCESS = 10105, /* 0x2779 */
MSP_ERROR_INVALID_PARA = 10106, /* 0x277A */ /* 缺少参数 */
MSP_ERROR_INVALID_PARA_VALUE = 10107, /* 0x277B */ /* 无效参数值 */
MSP_ERROR_INVALID_HANDLE = 10108, /* 0x277C */
MSP_ERROR_INVALID_DATA = 10109, /* 0x277D */
MSP_ERROR_NO_LICENSE = 10110, /* 0x277E */ /* 引擎授权不足 */
MSP_ERROR_NOT_INIT = 10111, /* 0x277F */ /* 引擎未初始化,可能是引擎崩溃 */
MSP_ERROR_NULL_HANDLE = 10112, /* 0x2780 */
MSP_ERROR_OVERFLOW = 10113, /* 0x2781 */ /* 单用户下模型数超上限(10个), */
/* 只出现在测试时对一个用户进行并发注册 */
MSP_ERROR_TIME_OUT = 10114, /* 0x2782 */ /* 超时 */
MSP_ERROR_OPEN_FILE = 10115, /* 0x2783 */
MSP_ERROR_NOT_FOUND = 10116, /* 0x2784 */ /* 数据库中模型不存在 */
MSP_ERROR_NO_ENOUGH_BUFFER = 10117, /* 0x2785 */
MSP_ERROR_NO_DATA = 10118, /* 0x2786 */ /* 从客户端读音频或从引擎段获取结果时无数据 */
MSP_ERROR_NO_MORE_DATA = 10119, /* 0x2787 */
MSP_ERROR_NO_RESPONSE_DATA = 10120, /* 0x2788 */
MSP_ERROR_ALREADY_EXIST = 10121, /* 0x2789 */ /* 数据库中模型已存在 */
MSP_ERROR_LOAD_MODULE = 10122, /* 0x278A */
MSP_ERROR_BUSY = 10123, /* 0x278B */
MSP_ERROR_INVALID_CONFIG = 10124, /* 0x278C */
MSP_ERROR_VERSION_CHECK = 10125, /* 0x278D */
MSP_ERROR_CANCELED = 10126, /* 0x278E */
MSP_ERROR_INVALID_MEDIA_TYPE = 10127, /* 0x278F */
MSP_ERROR_CONFIG_INITIALIZE = 10128, /* 0x2790 */
MSP_ERROR_CREATE_HANDLE = 10129, /* 0x2791 */
MSP_ERROR_CODING_LIB_NOT_LOAD = 10130, /* 0x2792 */
MSP_ERROR_USER_CANCELLED = 10131, /* 0x2793 */
MSP_ERROR_INVALID_OPERATION = 10132, /* 0x2794 */
MSP_ERROR_MESSAGE_NOT_COMPLETE = 10133, /* 0x2795 */ /* flash */
MSP_ERROR_NO_EID = 10134, /* 0x2795 */
MSP_ERROE_OVER_REQ = 10135, /* 0x2797 */ /* client Redundancy request */
MSP_ERROR_USER_ACTIVE_ABORT = 10136, /* 0x2798 */ /* user abort */
MSP_ERROR_BUSY_GRMBUILDING = 10137, /* 0x2799 */
MSP_ERROR_BUSY_LEXUPDATING = 10138, /* 0x279A */
MSP_ERROR_SESSION_RESET = 10139, /* 0x279B */ /* msc主动终止会话,准备重传 */
MSP_ERROR_BOS_TIMEOUT = 10140, /* 0x279C */ /* VAD前端点超时 */
MSP_ERROR_STREAM_FILTER = 10141, /* 0X279D */ /* AIUI当前Stream被过滤 */
MSP_ERROR_STREAM_CLEAR = 10142, /* 0X279E */ /* AIUI当前Stream被清理 */
/* Error codes of network 10200(0x27D8)*/
MSP_ERROR_NET_GENERAL = 10200, /* 0x27D8 */
MSP_ERROR_NET_OPENSOCK = 10201, /* 0x27D9 */ /* Open socket */
MSP_ERROR_NET_CONNECTSOCK = 10202, /* 0x27DA */ /* Connect socket */
MSP_ERROR_NET_ACCEPTSOCK = 10203, /* 0x27DB */ /* Accept socket */
MSP_ERROR_NET_SENDSOCK = 10204, /* 0x27DC */ /* Send socket data */
MSP_ERROR_NET_RECVSOCK = 10205, /* 0x27DD */ /* Recv socket data */
MSP_ERROR_NET_INVALIDSOCK = 10206, /* 0x27DE */ /* Invalid socket handle */
MSP_ERROR_NET_BADADDRESS = 10207, /* 0x27EF */ /* Bad network address */
MSP_ERROR_NET_BINDSEQUENCE = 10208, /* 0x27E0 */ /* Bind after listen/connect */
MSP_ERROR_NET_NOTOPENSOCK =

本文介绍了一个使用Unity制作的批量配音工具,通过调用讯飞语音合成API,实现了文本到语音的转换,并提供了详细的代码实现和配置流程。
最低0.47元/天 解锁文章
771

被折叠的 条评论
为什么被折叠?



