線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2407
推到 Plurk!
推到 Facebook!

繁體轉簡體後無法用Microsoft Speech SDK 5.1 發音

答題得分者是:taishyang
juneo
高階會員


發表:103
回覆:190
積分:118
註冊:2004-05-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-02-06 16:15:03 IP:140.114.xxx.xxx 訂閱
我想做一個可以發出中文語音的程式
使用Microsoft Speech SDK 5.1
所以需要將繁體轉成簡體
目前已經轉好,但是卻遇上不能夠發音?
請問有人知道該怎麼讓 speech 發音嗎?

以下是程式碼與程式附加檔案

[code cpp]
//---------------------------------------------------------------------------
#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SpeechLib_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
//
}
//---------------------------------------------------------------------------
//enum CharSet {UNICODE=0, SJIS=932, GB3212=936, BIG5=950, EUC_KR=949};
// GB to BIG5
AnsiString __fastcall TForm1::GBToBig5(const AnsiString str)
{
PWSTR wszUnicode = NULL; //Unicode
PSTR InStr = NULL; //from Code
PSTR OutStr = NULL; //to Code
int iLen = 0; //char length

InStr = (char*)str.c_str();
int InSize = str.Length();
iLen = MultiByteToWideChar(936,0,InStr,InSize,NULL,0);
wszUnicode = new wchar_t[iLen 1];
MultiByteToWideChar(936,0,InStr,InSize,wszUnicode,iLen);

// 簡轉繁
PWSTR wszUnicode2 = new wchar_t[iLen 1];
LCMapStringW(0x0404, // Locale id of taiwan
LCMAP_TRADITIONAL_CHINESE,
wszUnicode, iLen,
wszUnicode2,iLen);

//unicode to other
int uiLen = WideCharToMultiByte(950,0,wszUnicode2,iLen,NULL,0,NULL,NULL);
OutStr = new char[uiLen 1];
WideCharToMultiByte(950,0,wszUnicode2,iLen,OutStr,uiLen,NULL,NULL);

AnsiString ret = AnsiString(OutStr);
delete [] OutStr ;
delete [] wszUnicode;
delete [] wszUnicode2 ;

return ret ;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TForm1::Big5ToGB(const AnsiString str)
{
PWSTR wszUnicode = NULL; //Unicode
PSTR InStr = NULL; //from Code
PSTR OutStr = NULL; //to Code
int iLen = 0; //char length

InStr = (char*)str.c_str();
int InSize = str.Length();
iLen = MultiByteToWideChar(950,0,InStr,InSize,NULL,0);
wszUnicode = new wchar_t[iLen 1];
MultiByteToWideChar(950,0,InStr,InSize,wszUnicode,iLen);

// 繁轉簡 請更改顯示的物件的 FONT 屬性 將字型改為 SimSum (簡體字體)
PWSTR wszUnicode2 = new wchar_t[iLen 1];
LCMapStringW(0x0404, // Locale id of taiwan
LCMAP_SIMPLIFIED_CHINESE,
wszUnicode, iLen,
wszUnicode2,iLen);

//unicode to other
int uiLen = WideCharToMultiByte(936,0,wszUnicode2,iLen,NULL,0,NULL,NULL);
OutStr = new char[uiLen 1];
WideCharToMultiByte(936,0,wszUnicode2,iLen,OutStr,uiLen,NULL,NULL);

AnsiString ret = AnsiString(OutStr);
delete [] OutStr ;
delete [] wszUnicode;
delete [] wszUnicode2 ;

return ret ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Edit2->Text = Big5ToGB(Edit1->Text);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Edit3->Text = GBToBig5(Edit2->Text);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
//Microsoft Speech SDK 5.1
ISpeechObjectTokensPtr sots,si;
sots = SpVoice1->GetVoices((WideString)"Language=804",(wchar_t*)""); //中文
SpVoice1->_set_Voice(sots->Item(0));

String s_Str = Edit2->Text;
WideString ws_CreateSound = (WideString)s_Str;
SpVoice1->set_Volume(300);
SpVoice1->Speak(ws_CreateSound,SVSFlagsAsync);
}
//---------------------------------------------------------------------------

[/code]

總結:
由taishyang大大的回覆後修改有問題的程式,並將改好的上傳,
編輯記錄
juneo 重新編輯於 2009-02-07 15:28:15, 註解 無‧
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-02-06 17:23:18 IP:118.169.xxx.xxx 訂閱
我參考這個連結幫你完成缺少的部份

1.
Big5ToGBUnicode
2.指定簡體中文發音

http://delphi.ktop.com.tw/board.php?cid=30&fid=74&tid=67751

[code cpp]
//---------------------------------------------------------------------------
//enum CharSet {UNICODE=0, SJIS=932, GB3212=936, BIG5=950, EUC_KR=949};
// GB to BIG5
AnsiString __fastcall TForm1::GBToBig5(const AnsiString str)
{
PWSTR wszUnicode = NULL; //Unicode
PSTR InStr = NULL; //from Code
PSTR OutStr = NULL; //to Code
int iLen = 0; //char length

InStr = (char*)str.c_str();
int InSize = str.Length();
iLen = MultiByteToWideChar(936,0,InStr,InSize,NULL,0);
wszUnicode = new wchar_t[iLen 1];
MultiByteToWideChar(936,0,InStr,InSize,wszUnicode,iLen);

// 簡轉繁
PWSTR wszUnicode2 = new wchar_t[iLen 1];
LCMapStringW(0x0404, // Locale id of taiwan
LCMAP_TRADITIONAL_CHINESE,
wszUnicode, iLen,
wszUnicode2,iLen);

//unicode to other
int uiLen = WideCharToMultiByte(950,0,wszUnicode2,iLen,NULL,0,NULL,NULL);
OutStr = new char[uiLen 1];
WideCharToMultiByte(950,0,wszUnicode2,iLen,OutStr,uiLen,NULL,NULL);

AnsiString ret = AnsiString(OutStr);
delete [] OutStr ;
delete [] wszUnicode;
delete [] wszUnicode2 ;

return ret ;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TForm1::Big5ToGB(const AnsiString str)
{
PWSTR wszUnicode = NULL; //Unicode
PSTR InStr = NULL; //from Code
PSTR OutStr = NULL; //to Code
int iLen = 0; //char length

InStr = (char*)str.c_str();
int InSize = str.Length();
iLen = MultiByteToWideChar(950,0,InStr,InSize,NULL,0);
wszUnicode = new wchar_t[iLen 1];
MultiByteToWideChar(950,0,InStr,InSize,wszUnicode,iLen);

// 繁轉簡 請更改顯示的物件的 FONT 屬性 將字型改為 SimSum (簡體字體)
PWSTR wszUnicode2 = new wchar_t[iLen 1];
LCMapStringW(0x0404, // Locale id of taiwan
LCMAP_SIMPLIFIED_CHINESE,
wszUnicode, iLen,
wszUnicode2,iLen);

//unicode to other
int uiLen = WideCharToMultiByte(936,0,wszUnicode2,iLen,NULL,0,NULL,NULL);
OutStr = new char[uiLen 1];
WideCharToMultiByte(936,0,wszUnicode2,iLen,OutStr,uiLen,NULL,NULL);

AnsiString ret = AnsiString(OutStr);
delete [] OutStr ;
delete [] wszUnicode;
delete [] wszUnicode2 ;

return ret ;
}
//---------------------------------------------------------------------------
WideString __fastcall TForm1::Big5ToGBUnicode(const AnsiString str)
{
WideString szResult;
int len;
AnsiString szBig5;
szBig5 = Big5ToGB(str);
len = szBig5.Length() 1;
szResult.SetLength(len);
len = MultiByteToWideChar(936, 0, szBig5.c_str(), -1, szResult.c_bstr(), len);
szResult.SetLength(len-1);
return szResult;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Edit2->Text = Big5ToGB(Edit1->Text);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Edit3->Text = GBToBig5(Edit2->Text);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
//Microsoft Speech SDK 5.1
ISpeechObjectTokensPtr sots, si;
SpObjectToken *ST;
sots = SpVoice1->GetVoices((wchar_t*)"", (wchar_t*)"");
for (int i=0; iCount; i ){
ST = sots->Item(i);
if (wcscmp(ST->GetDescription(i), L"Microsoft Simplified Chinese") == 0){
SpVoice1->_set_Voice(sots->Item(i));
break;
}
}

WideString ws_CreateSound = Big5ToGBUnicode(Edit1->Text);
SpVoice1->set_Volume(300);
SpVoice1->Speak(ws_CreateSound, SVSFlagsAsync);
}
//---------------------------------------------------------------------------

[/code]
編輯記錄
taishyang 重新編輯於 2009-02-06 17:24:08, 註解 無‧
taishyang 重新編輯於 2009-02-06 19:06:37, 註解 無‧
taishyang 重新編輯於 2009-02-06 19:07:43, 註解 無‧
taishyang 重新編輯於 2009-02-06 19:08:35, 註解 無‧
taishyang 重新編輯於 2009-02-06 19:10:25, 註解 無‧
juneo
高階會員


發表:103
回覆:190
積分:118
註冊:2004-05-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-02-07 15:23:44 IP:140.114.xxx.xxx 訂閱
感謝大大的指導,實際操作後需要修改下面這行,就可以執行 ^^
if (wcscmp(ST->GetDescription(i), L"Microsoft Simplified Chinese") == 0) //簡體

[code cpp]
void __fastcall TForm1::Button3Click(TObject *Sender)
{
//Microsoft Speech SDK 5.1
ISpeechObjectTokensPtr sots, si;
SpObjectToken *ST;
sots = SpVoice1->GetVoices((wchar_t*)"", (wchar_t*)"");
for (int i=0; iCount; i )
{
ST = sots->Item(i);
if (wcscmp(ST->GetDescription(i), L"Microsoft Simplified Chinese") == 0) //簡體
{
SpVoice1->_set_Voice(sots->Item(i));
break;
}
}

WideString ws_CreateSound = Big5ToGBUnicode(Edit1->Text);
SpVoice1->set_Volume(300);
SpVoice1->Speak(ws_CreateSound, SVSFlagsAsync);
}
//---------------------------------------------------------------------------

[/code]
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2009-02-09 00:40:00 IP:218.168.xxx.xxx 訂閱
這是站上顯示的問題,反應許久都沒有改善 ^^|
實際上
ST->GetDescription(i)
應該是
ST->GetDescription(i)
系統時間:2024-11-25 16:20:11
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!