c 呼叫開源espeak語音引擎實現中英文混讀

2021-10-06 16:24:03 字數 3669 閱讀 7310

實際.net專案中需要用到tts(文字轉語音技術),實現語音播服務,需要中英文混讀

1,微軟tts語音引擎。

呼叫非常簡單 ,也是我首先採用的方案,可參考如下微博:

但有個缺點:依賴windows平台的語音引擎與speech api,使用過程中會發現:有的系統能用,有的系統用不了(據說是閹割版系統所致);非中文版系統更慘,需要各種操作安裝中文語音包,最後安裝好了,可能發現還是用不了(專案中血淋淋的教訓:windows server英文版系統,各種折騰最後用不了,甲方伺服器,又不能隨便重灌系統),於是替代方案。

2,espeak方案

[

dllimport

("espeak_lib.dll"

, charset = charset.auto, callingconvention = callingconvention.cdecl)

]static extern error espeak_setvoicebyname([

marshalas

(unmanagedtype.lputf8str)

] string name);[

dllimport

("espeak_lib.dll"

, charset = charset.auto, callingconvention = callingconvention.cdecl)

]static extern error espeak_setparameter

(parameter parameter, int value, parametertype type);[

dllimport

("espeak_lib.dll"

, charset = charset.auto, callingconvention = callingconvention.cdecl)

]static extern error espeak_synchronize()

;[dllimport

("espeak_lib.dll"

, charset = charset.auto, callingconvention = callingconvention.cdecl)

]static extern error espeak_terminate()

;[dllimport

("espeak_lib.dll"

, charset = charset.auto, callingconvention = callingconvention.cdecl)

]static extern intptr espeak_getcurrentvoice()

;[dllimport

("espeak_lib.dll"

, charset = charset.auto, callingconvention = callingconvention.cdecl)

]static extern error espeak_synth([

marshalas

(unmanagedtype.lputf8str)

] string text, int size, uint startposition =

0, positiontype positiontype = positiontype.character, uint endposition =

0, speechflags flags = speechflags.charsutf8, uintptr uniqueidentifier =

default

(uintptr)

, intptr userdata =

default

(intptr));

[dllimport

("espeak_lib.dll"

, charset = charset.auto, callingconvention = callingconvention.cdecl)

]static extern int espeak_initialize

(audiooutput output, int bufferlength, intptr path, int options);[

dllimport

("espeak_lib.dll"

, charset = charset.auto, callingconvention = callingconvention.cdecl)

]static extern error espeak_cancel()

;[dllimport

("espeak_lib.dll"

, charset = charset.auto, callingconvention = callingconvention.cdecl)

]static extern void

espeak_setsynthcallback

(eventhandler.synthcallback callback)

;

public

static

void

initialize

(string path)

?", path));

}espeak_setsynthcallback

(eventhandler.handle)

; initialized =

true;}

public

static bool setrate

(int rate)

var result =

espeak_setparameter

(parameter.rate, rate, parametertype.absolute)

;return

checkresult

(result);}

static bool checkresult

(error result)

else

if(result == error.

ee_buffer_full

)else

if(result == error.

ee_internal_error

)else

}public

static bool speak

(string text)

public

static bool speakssml

(string text)

public

static bool stop()

public

static bool espeak_synchronize()

public

static bool espeak_terminate()

public

static bool setvoicebyname

(string name)

public

static voice getcurrentvoice()

return

newvoice()

;}

class

program

}

因該模組開發主要得益於開源,故將原始碼開源:

C 呼叫MatLab引擎

1.確保本機安裝matlab 2.c 程式中新增對matlab的引用 安裝目錄下的mwarray.dll 4.指定matlab執行m檔案的路徑 預先寫好的m檔案存在本地目錄下,當前存在程式執行目錄下 string command string.emptry 定義命令列要執行的字串 string pa...

C 呼叫微軟自帶的語音識別

using system using system.collections.generic using system.linq using system.text using system.speech.recognition 引用系統的speech的識別 using system.speech.s...

C 呼叫訊飛實時語音轉寫

websocket呼叫訊飛介面類 using iflycalc.entity using iflycalc.utils using iflycalc.view using system using system.collections using system.text using system.t...