基本思想:文字转语音测试代码,支持中英文
cmakelists.txt
# cmake_minimum_required(VERSION <specify CMake version here>)
project(untitled7)
set(CMAKE_CXX_STANDARD 14)
add_executable(untitled7 main.cpp)
target_link_libraries(untitled7 -lespeak)
#sudo apt-get install espeak libespeak-dev
#sudo apt-get install festival
代码
#include <stdio.h>
#include <string.h>
#include <espeak/speak_lib.h>
int main(int argc, char* argv[]) {
const char* text = "i love china";
int rc;
espeak_POSITION_TYPE position_type;
espeak_AUDIO_OUTPUT output;
char *path=NULL;
int Buflength = 500, Options=0;
void* user_data;
t_espeak_callback *SynthCallback;
espeak_PARAMETER Parm;
unsigned int Size,position=0, end_position=0, flags=espeakCHARS_AUTO, *unique_identifier;
output = AUDIO_OUTPUT_PLAYBACK;
espeak_Initialize(output, Buflength, path, Options );
espeak_SetVoiceByName("zh"); // 设置语言为英文en 中文 zh
Size = strlen(text)+1;
espeak_Synth( text, Size, position, position_type, end_position, flags, unique_identifier, user_data );
espeak_Synchronize( );
espeak_Terminate();
return 0;
}