首页 >> 租房准备

语音合成与识别技术在中的应用覆盖

2021-09-06 来源:临清租房网

在.net中,对英文语音有较好的支持,但是对中文语音的支持还没有加入进来,我们要想实现中文发音或中文语音识别,必需先安装微软的Speech Application SDK(SASDK),它的最新版本是 SAPI 5.1 他能够识别中、日、英三种语言,你可以在这里下载:需要安装这两个文件Speech SDK 5.1和5.1 Language Pack,其中5.1 Language Pack可以选择安装支持的语言。

安装好以后,我们就可以开始进行语音程序的开发了,当然,在这之前我们需要把l通过如下图所示添加到引用中

下面我们设计一个能够朗读中英文混合语言的类:

我们将用单例模式实现该类,类的代码如下,我们将详细解释:

public class Speach

{

private static Speach _Instance = null ;

private VoiceClass voice =null;

private Speach()

{

BuildSpeach() ;

}

public static Speach instance()

{

if (_Instance == null)

_Instance = new Speach() ;

return _Instance ;

}

private void SetChinaVoice()

{

ice = tVoices(pty,pty).Item(0) ;

}

private void SetEnglishVoice()

{

ice = tVoices(pty,pty).Item(1) ;

}

private void SpeakChina(string strSpeak)

{

SetChinaVoice() ;

Speak(strSpeak) ;

}

private void SpeakEnglishi(string strSpeak)

{

SetEnglishVoice() ;

Speak(strSpeak) ;

}

public void AnalyseSpeak(string strSpeak)

{

int iCbeg = 0 ;

int iEbeg = 0 ;

bool IsChina = true ;

for(int i=0;ngth;i++)

{

char chr = strSpeak[i] ;

if (IsChina)

{

if (chr=122chr=65)

{

int iLen = i - iCbeg ;

string strValue = bstring(iCbeg,iLen) ;

SpeakChina(strValue) ;

iEbeg = i ;

IsChina = false ;

}

}

else

{

if (chr122||chr65)

{

int iLen = i - iEbeg ;

string strValue = bstring(iEbeg,iLen) ;

eakEnglishi(strValue) ;

iCbeg = i ;

IsChina = true ;

}

}

}//end for

if (IsChina)

{

int iLen = ngth - iCbeg ;

string strValue = bstring(iCbeg,iLen) ;

SpeakChina(strValue) ;

}

else

{

int iLen = ngth - iEbeg ;

你还可以融合装备哦!当然 string strValue = bstring(iEbeg,iLen) ;

SpeakEnglishi(strValue) ;

}

}

private void BuildSpeach()

{

if (voice == null)

voice = new SpVoiceClass() ;

}

public int Volume

{

get

{

return lume ;

}

set

{

tVolume((ushort)(value)) ;

}

}

public int Rate

{

get

{

return te ;

}

set

{

tRate(value) ;

}

}

private void Speak(string strSpeack)

{

try

{

eak(strSpeack,SFlagsAsync) ;

}

catch(Exception err)

{

throw(new Exception(\"发生一个错误:\"+ssage)) ;

}

}

public void Stop()

{

eak(pty,SFPurgeBeforeSpeak) ;

}

public void Pause()

{

use() ;

}

public void Continue()

{

sume() ;

}

}//end class

在 private VoiceClass voice =null;这里,我们定义个一个用来发音的类,并且在第一次调用该类时,对它用BuildSpeach方法进行了初始化。

我们还定义了两个属性Volume和Rate,能够设置音量和语速。

我们知道,SpVoiceClass 有一个Speak方法,我们发音主要就是给他传递一个字符串,它负责读出该字符串,如下所示。

private void Speak(string strSpeack)

{

try

{

eak(strSpeack,SFlagsAsync) ;

}

catch(Exception err)

{

throw(new Exception(\"发生一个错误:\"+ssage)) ;

}

}

其中SFlagsAsync表示异步发音。

银川宫颈糜烂
呼和浩特哪医院治疗男科好
霉菌性阴道炎白带特别多是什么原因