本页内容

QVoice Class

QVoice 类表示一种特定的语音。更多内容...

标题: #include <QVoice>
CMake: find_package(Qt6 REQUIRED COMPONENTS TextToSpeech)
target_link_libraries(mytarget PRIVATE Qt6::TextToSpeech)
qmake: QT += texttospeech

公共类型

enum Age { Child, Teenager, Adult, Senior, Other }
enum Gender { Male, Female, Unknown }

属性

  • (since 6.4) locale : const QLocale
  • name : const QString

公共函数

QVoice()
QVoice(const QVoice &other)
QVoice(QVoice &&other)
~QVoice()
QVoice::Age age() const
QVoice::Gender gender() const
QLocale::Language language() const
QLocale locale() const
QString name() const
(since 6.4) void swap(QVoice &other)
QVoice &operator=(QVoice &&other)
QVoice &operator=(const QVoice &other)

静态公共成员

QString ageName(QVoice::Age age)
QString genderName(QVoice::Gender gender)
bool operator!=(const QVoice &lhs, const QVoice &rhs)
(since 6.4) QDataStream &operator<<(QDataStream &stream, const QVoice &voice)
(since 6.4) QDebug operator<<(QDebug debug, const QVoice &voice)
bool operator==(const QVoice &lhs, const QVoice &rhs)
(since 6.4) QDataStream &operator>>(QDataStream &stream, QVoice &voice)

详细说明

要获取当前文本转语音引擎支持的语音,请使用QTextToSpeech::availableVoices() 或QTextToSpeech::findVoices()。

成员类型文档

enum QVoice::Age

声音的年代。

恒定值描述
QVoice::Child0孩童的声音
QVoice::Teenager1青少年的声音
QVoice::Adult2成年人的声音
QVoice::Senior3老年人的声音
QVoice::Other4年龄不详者的声音

enum QVoice::Gender

声音的性别。

常量值描述
QVoice::Male0男性声音
QVoice::Female1女性的声音
QVoice::Unknown2性别不明的声音

属性文档

[read-only] age : const Age

该属性保存声音的年龄

访问功能:

QVoice::Age age() const

[read-only] gender : const Gender

该属性存储声音的性别

访问函数:

QVoice::Gender gender() const

[read-only, since 6.6] language : QLocale::Language

该属性用于指定语音的语言

这是语音的locale 的language 属性。

该枚举类型在 Qt 6.6 中引入。

访问函数:

QLocale::Language language() const

[read-only, since 6.4] locale : const QLocale

此属性存储语音的区域设置

该区域设置包含语音的语言和地域(即口音或方言)。

该枚举在 Qt 6.4 中引入。

访问函数:

QLocale locale() const

[read-only] name : const QString

该属性存储语音的名称

Access 函数:

QString name() const

成员函数文档

QVoice::QVoice()

创建一个空的 QVoice 实例。

应用程序代码不能创建任意的语音实例。请改用QTextToSpeech::availableVoices() 或QTextToSpeech::findVoices() 来选择受支持的语音。

[noexcept] QVoice::QVoice(const QVoice &other)

从other 复制并构造一个 QVoice 对象。

[constexpr noexcept default] QVoice::QVoice(QVoice &&other)

通过从other 读取数据来创建一个 QVoice 对象。

[noexcept] QVoice::~QVoice()

销毁QVoice 实例。

[static] QString QVoice::ageName(QVoice::Age age)

返回一个字符串,该字符串表示该语音的age 类。

[static] QString QVoice::genderName(QVoice::Gender gender)

̈́ 返回一个语音的gender 名称。

[noexcept, since 6.4] void QVoice::swap(QVoice &other)

将other 替换为该语音。此操作速度极快,且从不会失败。

该函数在 Qt 6.4 中引入。

[noexcept] QVoice &QVoice::operator=(QVoice &&other)

将other 移入此QVoice 对象中。

[noexcept] QVoice &QVoice::operator=(const QVoice &other)

将other 分配给此QVoice 对象。

相关的非成员

[noexcept] bool operator!=(const QVoice &lhs, const QVoice &rhs)

返回lhs 语音与rhs 语音是否不同的结果。

[since 6.4] QDataStream &operator<<(QDataStream &stream, const QVoice &voice)

将voice 序列化为数据流stream 。

该函数在 Qt 6.4 中引入。

另请参阅 《Qt 数据类型的序列化》。

[since 6.4] QDebug operator<<(QDebug debug, const QVoice &voice)

将voice 的相关信息写入debug 流。

该函数于 Qt 6.4 中引入。

另请参阅 QDebug 。

[noexcept] bool operator==(const QVoice &lhs, const QVoice &rhs)

返回lhs 语音与rhs 语音是否相同。

如果name 、locale 、gender 和age 相同,且它们属于同一文本转语音引擎,则这两个语音被视为相同。

[since 6.4] QDataStream &operator>>(QDataStream &stream, QVoice &voice)

从数据流stream 中反序列化voice 。

该函数在 Qt 6.4 中引入。

另请参阅 《Qt 数据类型的序列化》。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.