如何在 Qt 中通过语音调度程序使用 RHVoice

问题描述 投票:0回答:1

我正在尝试在 Linux 上的 Qt C++ 项目中使用 RHVoice

我安装了RHVoice,并且我在它的库

RHVoice.h
中苦苦挣扎,它是由
librhvoice-dev
包提供的,到目前为止,这似乎是一个死胡同。

然后我发现Speech-Dispatcher支持RHVoice模块,并且Qt Text To Speech支持Speech-Dispatcher,所以这似乎是在Qt中使用RHVoice的正确方法。

但是Qt文档说:

语音调度程序引擎不支持任何引擎特定参数。

所以我无法让Speech-Dispatcher通过Qt使用RHVoice,我的问题基本上是如何解决这个限制?

c++ qt text-to-speech
1个回答
0
投票

解决此问题的一种方法是将 RHVoice 设置为 Speech-Dispatcher 的默认合成器,可以按如下方式完成:

通过修改以下文件来修改 Speech-Dispatcher 配置:

/usr/share/speech-dispatcher/conf/speechd.conf
/etc/speech-dispatcher/speechd.conf

如果您只想更改每个用户的配置,编辑以下文件就足够了:

~/.config/speech-dispatcher/speechd.conf

DefaultModule
更改为
rhvoice
,如下所示:

...
# -----OUTPUT MODULES CONFIGURATION-----
...
# The DefaultModule selects which output module is the default.  You
# must use one of the names of the modules loaded with AddModule.

DefaultModule rhvoice

保存并关闭,并检查它是否在您的Qt项目中工作,这是一个示例:

CMake:

cmake_minimum_required(VERSION 3.14)

project(RHVoiceSpeechD LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core TextToSpeech)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core TextToSpeech)

add_executable(RHVoiceSpeechD
  main.cpp
)
target_link_libraries(RHVoiceSpeechD Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::TextToSpeech)

install(TARGETS RHVoiceSpeechD
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

main.cpp

#include <QCoreApplication>
#include <QTextToSpeech>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QTextToSpeech *tts = new QTextToSpeech();

    //set speechd as the engine if it is not the default engine
    tts->setEngine("speechd");

    //test it
    tts->say("I'm using RHVoice as a synthesizer");

    return a.exec();
}

在终端中运行此命令:

spd-say -o rhvoice "I'm using RHVoice as a synthesizer"

并将音频输出与您的 Qt 项目中的音频输出进行比较,如果前面的步骤有效,它们听起来应该是相同的,RHVoice 的默认语音是“Alan”。

来源:

© www.soinside.com 2019 - 2024. All rights reserved.