Onnxruntime
ONNX Runtime 載入器。屬於行程層級的單例,每個行程僅存在一個實例。
方法
| 方法 | 說明 |
|---|---|
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 | 回傳已更新音節音高與音素長度的新重音短語。 |
replacePhonemeLength(string $accentPhrasesJson, int $styleId): string | 回傳已更新音素長度的新重音短語。 |
replaceMoraPitch(string $accentPhrasesJson, int $styleId): string | 回傳已更新音節音高的新重音短語。 |
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 產生歌唱合成查詢 JSON。 |
frameSynthesis(string $frameAudioQueryJson, int $styleId): string | 從影格音訊查詢合成歌唱聲音。回傳 WAV 二進位。 |
createSingFrameF0(string $scoreJson, string $frameAudioQueryJson, int $styleId): string | 從樂譜與歌唱查詢,以 JSON 的 float 陣列回傳每個影格的 F0(基頻)。 |
createSingFrameVolume(string $scoreJson, string $frameAudioQueryJson, int $styleId): string | 從樂譜與歌唱查詢,以 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 | 確認樂譜與歌唱音訊合成查詢的組合是否有效。若不合法會擲出 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 | 接尾詞 |