Onnxruntime
ONNX Runtime 加载器。是进程级单例,每个进程只有 1 个实例。
方法
| 方法 | 说明 |
|---|---|
static loadOnce(string $filename = ''): self | 加载并初始化 ONNX Runtime。第 2 次及以后调用时会忽略参数并返回已有实例。 |
static get(): ?self | 返回已有实例。若尚未初始化则返回 null。 |
supportedDevices(): string | 以 JSON 字符串返回可用设备信息。 |
static libRecommendedVersionedFilename(): string | 返回推荐的带版本号的 ONNX Runtime 库文件名(例如 libvoicevox_onnxruntime.1.23.2.dylib)。 |
static libRecommendedUnversionedFilename(): string | 返回推荐的不带版本号的 ONNX Runtime 库文件名。 |
static libMinRequiredMinorVersion(): int | 返回所支持的 ONNX Runtime 1.x 的最低次版本号。 |
static libMaxSupportedMinorVersion(): int | 返回所支持的 ONNX Runtime 1.x 的最高次版本号。 |
libVersionedFilename() 和 libUnversionedFilename() 作为已弃用的别名保留。
常量
| 常量 | 说明 |
|---|---|
LIB_MIN_REQUIRED_MINOR_VERSION | 所支持的 ONNX Runtime 1.x 的最低次版本号(17) |
LIB_MAX_SUPPORTED_MINOR_VERSION | 所支持的 ONNX Runtime 1.x 的最高次版本号(29) |
LIB_RECOMMENDED_NAME | 推荐的库基础名(voicevox_onnxruntime) |
LIB_RECOMMENDED_VERSION | 推荐的 ONNX Runtime 版本(1.23.2) |
LIB_NAME 和 LIB_VERSION 作为已弃用的别名保留。
OpenJtalk
使用 OpenJTalk 的文本分析器。
方法
| 方法 | 说明 |
|---|---|
__construct(string $openJtalkDictDir) | 使用 OpenJTalk 词典目录路径初始化。 |
analyze(string $text): string | 分析日语文本,返回重音短语数组的 JSON。 |
useUserDict(UserDict $userDict): void | 应用用户词典。若词典变更,需要再次调用。 |
VoiceModelFile
语音模型文件(.vvm 文件)。
方法
| 方法 | 说明 |
|---|---|
static open(string $path): self | 打开 .vvm 文件。 |
id(): string | 以 hex 字符串(16 字节)返回语音模型 ID。 |
createMetasJson(): string | 以 JSON 字符串返回说话人元数据。 |
close(): void | 关闭文件并释放资源。 |
Synthesizer
文本朗读的主要类。
方法
| 方法 | 说明 |
|---|---|
__construct(Onnxruntime $onnxruntime, OpenJtalk $openJtalk, AccelerationMode $accelerationMode = Auto, int $cpuNumThreads = 0) | 初始化合成器。 |
onnxruntime(): Onnxruntime | 返回该合成器持有的 Onnxruntime 实例。 |
isGpuMode(): bool | 返回是否启用了 GPU 模式。 |
metas(): string | 以 JSON 字符串返回已加载说话人的元数据。 |
loadVoiceModel(VoiceModelFile $model, OnExistingVoiceModelId $onExisting = Error): void | 加载语音模型。可通过 $onExisting 选择已加载相同 ID 模型时的行为。 |
unloadVoiceModel(string $voiceModelId): void | 卸载由 hex ID 指定的语音模型。 |
isLoadedVoiceModel(string $voiceModelId): bool | 检查语音模型是否已加载。 |
createAudioQuery(string $text, int $styleId): string | 从日语文本生成 AudioQuery JSON。 |
createAudioQueryFromKana(string $kana, int $styleId): string | 从 AquesTalk 风格的假名记法生成 AudioQuery JSON。 |
createAccentPhrases(string $text, int $styleId): string | 从日语文本生成重音短语数组 JSON。 |
createAccentPhrasesFromKana(string $kana, int $styleId): string | 从假名记法生成重音短语数组 JSON。 |
replaceMoraData(string $accentPhrasesJson, int $styleId): string | 返回已更新 mora 音高与音素时长的新重音短语。 |
replacePhonemeLength(string $accentPhrasesJson, int $styleId): string | 返回已更新音素时长的新重音短语。 |
replaceMoraPitch(string $accentPhrasesJson, int $styleId): string | 返回已更新 mora 音高的新重音短语。 |
synthesis(string $audioQueryJson, int $styleId, bool $enableInterrogativeUpspeak = true): string | 从 AudioQuery JSON 合成音频。返回 WAV 二进制。 |
createAudioFeature(string $audioQueryJson, int $styleId, bool $enableInterrogativeUpspeak = true): AudioFeature | 创建用于按帧 render 的中间表示 AudioFeature。 |
tts(string $text, int $styleId, bool $enableInterrogativeUpspeak = true): string | 从日语文本一步合成音频。返回 WAV 二进制。 |
ttsFromKana(string $kana, int $styleId, bool $enableInterrogativeUpspeak = true): string | 从假名记法合成音频。返回 WAV 二进制。 |
createSingFrameAudioQuery(string $scoreJson, int $styleId): string | 从乐谱 JSON 生成歌唱合成 query JSON。 |
frameSynthesis(string $frameAudioQueryJson, int $styleId): string | 从 frame audio query 合成歌唱音频。返回 WAV 二进制。 |
createSingFrameF0(string $scoreJson, string $frameAudioQueryJson, int $styleId): string | 从乐谱与歌唱 query 以 JSON 的 float 数组返回按帧的 F0(基频)。 |
createSingFrameVolume(string $scoreJson, string $frameAudioQueryJson, int $styleId): string | 从乐谱与歌唱 query 以 JSON 的 float 数组返回按帧的音量。 |
AudioFeature 与 AudioFeatureSlice
AudioFeature 拥有原生的中间表示,AudioFeatureSlice 则持有其所属的 AudioFeature。render 同步执行,返回 16-bit PCM 原始数据。
| 类 / 方法 | 说明 |
|---|---|
AudioFeature::length(): int | 返回总帧数。 |
AudioFeature::isEmpty(): bool | 返回 AudioFeature 是否为空。 |
AudioFeature::whole(): AudioFeatureSlice | 返回表示整体的 slice。 |
AudioFeature::slice(int $startInclusive, int $end, bool $endIsInclusive = false, bool $clamp = false, bool $allowStartExceedsEnd = false): AudioFeatureSlice | 创建表示帧范围的 slice。默认不包含结束位置。 |
AudioFeature::render(): string | 将整体 render 为 PCM。 |
AudioFeatureSlice::length(): int | 返回 slice 的帧数。 |
AudioFeatureSlice::isEmpty(): bool | 返回 slice 是否为空。 |
AudioFeatureSlice::slice(int $startInclusive, int $end, bool $endIsInclusive = false, bool $clamp = false, bool $allowStartExceedsEnd = false): AudioFeatureSlice | 使用相同的范围选项创建子 slice。 |
AudioFeatureSlice::render(): string | 将 slice render 为 PCM。 |
VoicevoxCore
VOICEVOX Core 的全局工具函数。
方法
| 方法 | 说明 |
|---|---|
getVersion(): string | 以 SemVer 字符串返回 VOICEVOX Core 的版本。 |
getFrameRate(): float | 返回每秒的帧数(CORE 0.17.1 中为 93.75)。 |
audioQueryFrameLength(string $audioQueryJson, bool $enableInterrogativeUpspeak = true): int | 返回音频的估计帧数。 |
audioQueryCreateFromAccentPhrases(string $accentPhrasesJson): string | 从重音短语数组 JSON 生成 AudioQuery JSON。 |
audioQueryValidate(string $audioQueryJson): void | 校验 AudioQuery JSON。不合法时抛出 VoicevoxException。 |
accentPhraseValidate(string $accentPhraseJson): void | 校验 AccentPhrase JSON。不合法时抛出 VoicevoxException。 |
moraValidate(string $moraJson): void | 校验 Mora JSON。不合法时抛出 VoicevoxException。 |
scoreValidate(string $scoreJson): void | 校验 Score JSON。不合法时抛出 VoicevoxException。 |
noteValidate(string $noteJson): void | 校验 Note JSON。不合法时抛出 VoicevoxException。 |
frameAudioQueryValidate(string $frameAudioQueryJson): void | 校验 FrameAudioQuery JSON。不合法时抛出 VoicevoxException。 |
framePhonemeValidate(string $framePhonemeJson): void | 校验 FramePhoneme JSON。不合法时抛出 VoicevoxException。 |
ensureCompatible(string $scoreJson, string $frameAudioQueryJson): void | 确认乐谱与歌唱合成 query 的组合是否有效。不合法时抛出 VoicevoxException。 |
UserDict
用于注册自定义词发音的用户词典。
方法
| 方法 | 说明 |
|---|---|
__construct() | 创建空的用户词典。 |
load(string $path): void | 从文件加载用户词典。 |
save(string $path): void | 将用户词典保存到文件。 |
addWord(string $surface, string $pronunciation, int $accentType, UserDictWordType $wordType = CommonNoun, int $priority = 5): string | 添加词。以 hex 字符串返回词 UUID。 |
updateWord(string $wordUuid, string $surface, string $pronunciation, int $accentType, UserDictWordType $wordType = CommonNoun, int $priority = 5): void | 更新由 UUID 指定的已有词。 |
removeWord(string $wordUuid): void | 删除由 UUID 指定的词。 |
importDict(UserDict $other): void | 从另一个 UserDict 导入词。 |
toJson(): string | 以 JSON 字符串返回所有词。 |
$priority 的取值范围为 0 至 10。传入超出范围的值时会抛出 InvalidArgumentException。
Enum:AccelerationMode
合成器的硬件加速模式。
| Case | 值 | 说明 |
|---|---|---|
Auto | 0 | 自动选择可用的最佳模式。 |
Cpu | 1 | 强制 CPU 模式。 |
Gpu | 2 | 强制 GPU 模式。 |
Enum:OnExistingVoiceModelId
在 Synthesizer::loadVoiceModel() 中,已加载相同 ID 的语音模型时的行为。
| Case | 值 | 说明 |
|---|---|---|
Error | 0 | 视为错误。这是默认行为。 |
Reload | 1 | 重新加载已有的语音模型。 |
Skip | 2 | 不做任何操作。 |
Enum:UserDictWordType
用户词典条目的词类。
| Case | 值 | 说明 |
|---|---|---|
ProperNoun | 0 | 专有名词 |
CommonNoun | 1 | 普通名词 |
Verb | 2 | 动词 |
Adjective | 3 | 形容词 |
Suffix | 4 | 后缀 |