跳转到主要内容

Onnxruntime

ONNX Runtime 加载器。是进程级单例,每个进程只有 1 个实例。

方法

方法说明
static loadOnce(string $filename = ''): self加载并初始化 ONNX Runtime。第 2 次及以后调用时会忽略参数并返回已有实例。
static get(): ?self返回已有实例。若尚未初始化则返回 null
supportedDevices(): string以 JSON 字符串返回可用设备信息。
static libVersionedFilename(): string返回带版本号的 ONNX Runtime 库文件名(例如 libvoicevox_onnxruntime.1.17.3.dylib)。
static libUnversionedFilename(): string返回不带版本号的 ONNX Runtime 库文件名。

常量

常量说明
LIB_NAME库的基础名(voicevox_onnxruntime
LIB_VERSION推荐的 ONNX Runtime 版本

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): void加载语音模型。
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 二进制。
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 数组返回按帧的音量。

VoicevoxCore

VOICEVOX Core 的全局工具函数。

方法

方法说明
static getVersion(): string以 SemVer 字符串返回 VOICEVOX Core 的版本。
static audioQueryCreateFromAccentPhrases(string $accentPhrasesJson): string从重音短语数组 JSON 生成 AudioQuery JSON。
static audioQueryValidate(string $audioQueryJson): void校验 AudioQuery JSON。不合法时抛出 VoicevoxException
static accentPhraseValidate(string $accentPhraseJson): void校验 AccentPhrase JSON。不合法时抛出 VoicevoxException
static moraValidate(string $moraJson): void校验 Mora JSON。不合法时抛出 VoicevoxException
static scoreValidate(string $scoreJson): void校验 Score JSON。不合法时抛出 VoicevoxException
static noteValidate(string $noteJson): void校验 Note JSON。不合法时抛出 VoicevoxException
static frameAudioQueryValidate(string $frameAudioQueryJson): void校验 FrameAudioQuery JSON。不合法时抛出 VoicevoxException
static framePhonemeValidate(string $framePhonemeJson): void校验 FramePhoneme JSON。不合法时抛出 VoicevoxException
static 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 字符串返回所有词。

Enum:AccelerationMode

合成器的硬件加速模式。
Case说明
Auto0自动选择可用的最佳模式。
Cpu1强制 CPU 模式。
Gpu2强制 GPU 模式。

Enum:UserDictWordType

用户词典条目的词类。
Case说明
ProperNoun0专有名词
CommonNoun1普通名词
Verb2动词
Adjective3形容词
Suffix4后缀

VoicevoxException

当 VOICEVOX Core 的 C API 调用返回错误码时抛出。异常消息中包含来自库的错误说明。
最后修改于 2026年7月13日