首页 > 解决方案 > FLite 不会从文件/festvox 存储库中加载语音

问题描述

我仍然在使用 FLite TTS 时遇到麻烦。将其构建到我的项目中(Ubuntu 16.04 上的 c++)后,我无法加载任何语音来执行 TTS 转换。我尝试了三种方法来初始化所需的声音,但没有成功。

起初我尝试了文档示例中的“register_cmu_us_kal”,但它带有许多构建错误,甚至无法编译,因为它找不到一些内部使用的函数。

后来尝试“flite_voice_select”只是为了在运行时崩溃(然后发现没有返回语音,因为语音列表是空的,我应该填充它吗?init方法不应该这样做吗?)

最后,我厌倦了“flite_voice_load”,并得到了一些关于出了什么问题的暗示,但它并没有出现问题。

使用“flite_voice_load”调用我得到以下结果:

2020-09-08T12:54:55.099821  DEBUG   TTSFliteManager::TTSTranslate()
Error load voice: lang/lex eng not supported in this binary
2020-09-08T12:55:01.588762  DEBUG   TTSFliteManager::TTSTranslate() voice list = 0
2020-09-08T12:55:01.588814  ERROR   TTSFliteManager::TTSTranslate() NO VOICE SELECTED 0

如果我做对了,它会找到 voice.flitevox 文件,但缺少其他东西,语言?词典?我不知道,尤其是因为我只使用 FLtie 本身提供的声音,所以我认为做得很好。查看函数签名我的理解是,在我加载语音之前,我不能使用“flite_add_voice”或“flite_add_lang”,那么我还缺少什么其他指令来在我的应用程序中实际加载语音文件来完成转换?

extern "C" {
cst_voice *register_cmu_us_kal(const char*);
}     
...
bool
TTSFliteManager::TTSTranslate(std::string text, std::string destination)
{
    ADD_LOG_DEBUG << "TTSFliteManager::TTSTranslate()";
    cst_voice *voice;
    flite_init();
//    std::string voiceName = "file:///home/user/download/cmu_us_aew.flitevox";
    std::string voiceName = "http://festvox.org/flite/packed/flite-2.0/voices/cmu_us_rxr.flitevox";

    voice = flite_voice_load(voiceName.c_str());
//    voice = flite_voice_select(voiceName.c_str());
//    voice = register_cmu_us_kal(NULL);
    
    
    ADD_LOG_DEBUG << "TTSFliteManager::TTSTranslate() voice list = " << flite_voice_list ;
    
    if(voice == nullptr)
    {
        ADD_LOG_ERROR << "TTSFliteManager::TTSTranslate() NO VOICE SELECTED " << voice;
        return false;
    }
    ADD_LOG_DEBUG << "TTSFliteManager::TTSTranslate() ready to convert text '" << text.c_str() << "' to destination '" << destination.c_str() << "' with voice '" << voice << "'";
    float secs = flite_text_to_speech(text.c_str(),voice,destination.c_str());
    if (secs == 0)
    {
        ADD_LOG_ERROR << "TTSFliteManager::TTSTranslate() ERROR GENERATED AUDIO FILE IS EMPTY";
        return false;
    }
    return true;
    
}

令我特别困惑和沮丧的是,从命令行它可以完美地工作,所以实际上它就在那里,只是看不到它。以下命令产生了一个完美可听的文件:

flite -voice file:///home/user/download/cmu_us_aew.flitevox -f /home/user/download/flite-2.0.0-release/doc/intro.txt -o intro.wav

标签: c++text-to-speechflite

解决方案


与 ALX23z 的废话相反,这里有一个解决方案(也许实际上阅读文档并尝试实施解决方案会更有帮助):

extern "C" {
cst_voice *register_cmu_us_rms(const char *voxdir);
void unregister_cmu_us_rms(cst_voice *v);
void usenglish_init(cst_voice *v);
cst_lexicon *cmulex_init(void);
}
    
bool
TTSFliteManager::TTSTranslate(std::string text, std::string destination)
{
    ADD_LOG_DEBUG << "TTSFliteManager::TTSTranslate()";
    cst_voice *voice;
    flite_init();
    std::string voiceName = "/home/user/download/cmu_us_rms.flitevox";
//    std::string voiceName = "http://festvox.org/flite/packed/flite-2.0/voices/cmu_us_rms.flitevox";
    flite_add_lang("eng",usenglish_init,cmulex_init);
    flite_add_lang("usenglish",usenglish_init,cmulex_init);

    voice = flite_voice_load(voiceName.c_str());    
    if(voice == nullptr)
    {
        ADD_LOG_ERROR << "TTSFliteManager::TTSTranslate() NO VOICE SELECTED " << voice;
        return false;
    }
    ADD_LOG_DEBUG << "TTSFliteManager::TTSTranslate() ready to convert text '" << text.c_str() << "' to destination '" << destination.c_str() << "' with voice '" << voice << "'";
    float secs = flite_text_to_speech(text.c_str(),voice,destination.c_str());
    if (secs == 0)
    {
        ADD_LOG_ERROR << "TTSFliteManager::TTSTranslate() ERROR GENERATED AUDIO FILE IS EMPTY";
        return false;
    }
    return true;
}

请注意,它与本地文件和远程文件完美配合,只需取消注释第二个“std::string voiceName”(并删除第一个)声明,让库从在线存储库下载语音,我去本地文件很明显性能原因。


推荐阅读