Ekho 的简单编程指南(中文文本转语音的引擎)

红薯 发布于 2012/05/06 20:28
阅读 3K+
收藏 2

Linux 平台

首先安装 Ekho,安装方法请看这里.

然后,编写如下示例:

/* file try.cpp */
#include "config.h" // this file is generated when building Ekho
#include "ekho.h"

using namespace ekho;

int main(int argc, char **argv) {
  Ekho wong("Cantonese");
  wong.blockSpeak("123");
  return 0;
}

接着使用如下命令进行编译:

$ g++ try.cpp libekho.a \
    lib/libSoundTouch.a lib/libFestival.a lib/libestools.a \
    lib/libeststring.a lib/libestbase.a \
    -I. -Iutfcpp/source -Isonic -pthread \
    -lvorbisenc -lvorbis -lm -logg -lmp3lame -lsndfile -lncurses \
    `pkg-config --libs libpulse-simple` \
    `pkg-config --cflags libpulse-simple`
$ ./a.out

接下来你可以检查 ekho.h 头文件中定义的 API,并继续进行测试。

Windows 平台

你可以通过 Windows 的 SAPI5 来使用 Ekho,你需要先安装 SAPI5 SDK,并阅读如何使用 SAPI5.

注意:Ekho 在 Windows 下还不支持英文。

#include "stdafx.h"
#include <iostream>
#include <sapi.h>
#include <sphelper.h>
#include <atlcom.h>

using namespace std;

int main ( int NumOfArguments, char** Argument )
{
    HRESULT hr = S_OK;
    CComPtr<IEnumSpObjectTokens> cpEnum;
    ULONG ulCount = 0;
    ISpVoice * pSpVoice = NULL;
    CComPtr<ISpObjectToken> cpToken;

    // Initialize COM
    CoInitialize(NULL);

    // Create the voice interface object
    if (FAILED(CoCreateInstance(CLSID_SpVoice, NULL, 
        CLSCTX_INPROC_SERVER, IID_ISpVoice, (void **)&pSpVoice))) {
        cerr << "Fail to create instance of ISpVoice!" << endl;
        return -1;
    }

    if (FAILED(SpEnumTokens(SPCAT_VOICES, L"Name=Ekho Cantonese", NULL, &cpEnum))) {
        cerr << "Fail to get voices!" << endl;
        return -1;
    }

    //Get the closest token
    if (FAILED(cpEnum->Next(1, &cpToken, NULL))) {
        cerr << "Fail to get voice EkhoVoice!" << endl;
        return -1;
    }

    //set the voice 
    if (FAILED(pSpVoice->SetVoice( cpToken))) {
        cerr << "Fail to set voice EkhoVoice!" << endl;
        return -1;
    }

    pSpVoice->Speak(L"123", SPF_DEFAULT, NULL);

    // Shutdown COM
    CoUninitialize ();

    return 0;
}

原文译自 Ekho 文档

加载中
0
zkool
zkool

灰常感谢红薯大侠的翻译

0
avence
avence

安装过程中,第一个小例子编译没过。错误提示如下:

Package libpulse-simple was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpulse-simple.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libpulse-simple' found
g++.real: 错误: libekho.a:没有那个文件或目录

 

求红薯大侠解答!!!!!非常紧急

0
KKiCC
KKiCC
感觉好复杂的说
返回顶部
顶部