基本信息
源码名称:本人共享:语音实时转写,C#实现
源码大小:11.47M
文件格式:.rar
开发语言:C#
更新时间:2019-12-30
   源码介绍

使用讯飞科技的语音API,实现语音实时转写




using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace 讯飞语音Windows
{
    public static class MSPDLL
    {
        [DllImport("msc.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Winapi)]
        public static extern int MSPLogin(string usr, string pwd, string param);
        [DllImport("msc.dll")]
        public static extern int MSPLogout();
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern IntPtr MSPGetVersion(string verName, ref int errorCode);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern IntPtr MSPUploadData(string dataName, IntPtr data, int dataLen, string param, ref int errorCode);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern int MSPSetParam(string paramName, string paramValue);
    }

    public partial class QTTS
    {
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern IntPtr QTTSSessionBegin(string param, ref int errorCode);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern int QTTSTextPut(string sessionID, string textString, int txtLen, string param);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern IntPtr QTTSAudioGet(string sessionID, ref int audioLen, ref int synthStatus, ref int errorCode);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern int QTTSSessionEnd(string sessionID, string hints);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern int QTTSGetParam(string sessionID, string paramName, string paramValue, ref int valueLen);
    }

    public partial class QISR
    {
        //typedef int ( *GrammarCallBack)( int, const char*, void*);
        //typedef int ( *LexiconCallBack)( int, const char*, void*);
        public delegate int GrammarCallBack(int errorCode, string info, IntPtr userData);
        public delegate int LexiconCallBack(int errorCode, string info, IntPtr userData);

        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern IntPtr QISRSessionBegin(string grammarList, string param, ref int errorCode);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern int QISRAudioWrite(string sessionID, IntPtr waveData, int waveLen, int audioStatus, ref int epStatus, ref int recogStatus);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern IntPtr QISRGetResult(string sessionID, ref int rsltStatus, int waitTime, ref int errorCode);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern int QISRSessionEnd(string sessionID, string hints);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern int QISRGetParam(string sessionID, string paramName, string paramValue, ref int valueLen);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern int QISRBuildGrammar(string grammarType, string grammarContent, int grammarLength, string param, GrammarCallBack callback, IntPtr userData);
        [DllImport("msc.dll", CharSet = CharSet.Ansi)]
        public static extern int QISRUpdateLexicon(string lexiconName, string lexiconContent, int lexiconLength, string param, LexiconCallBack callback, IntPtr userData);
    }
}