Onnxruntime
ONNX Runtime loader. This is a process-level singleton — only one instance exists per process.
Methods
| Method | Description |
|---|---|
static loadOnce(string $filename = ''): self | Loads and initializes the ONNX Runtime. On subsequent calls the argument is ignored and the existing instance is returned. |
static get(): ?self | Returns the existing instance, or null if not yet initialized. |
supportedDevices(): string | Returns available device information as a JSON string. |
static libRecommendedVersionedFilename(): string | Returns the recommended versioned filename of the ONNX Runtime library (e.g., libvoicevox_onnxruntime.1.23.2.dylib). |
static libRecommendedUnversionedFilename(): string | Returns the recommended unversioned filename of the ONNX Runtime library. |
static libMinRequiredMinorVersion(): int | Returns the minimum supported ONNX Runtime 1.x minor version. |
static libMaxSupportedMinorVersion(): int | Returns the maximum supported ONNX Runtime 1.x minor version. |
libVersionedFilename() and libUnversionedFilename() remain as deprecated aliases.
Constants
| Constant | Description |
|---|---|
LIB_MIN_REQUIRED_MINOR_VERSION | Minimum supported ONNX Runtime 1.x minor version (17) |
LIB_MAX_SUPPORTED_MINOR_VERSION | Maximum supported ONNX Runtime 1.x minor version (29) |
LIB_RECOMMENDED_NAME | Recommended library base name (voicevox_onnxruntime) |
LIB_RECOMMENDED_VERSION | Recommended ONNX Runtime version (1.23.2) |
LIB_NAME and LIB_VERSION remain as deprecated aliases.
OpenJtalk
Text analyzer using OpenJTalk.
Methods
| Method | Description |
|---|---|
__construct(string $openJtalkDictDir) | Initializes with the path to the OpenJTalk dictionary directory. |
analyze(string $text): string | Analyzes Japanese text and returns an accent phrase array as a JSON string. |
useUserDict(UserDict $userDict): void | Applies a user dictionary. Call again if the dictionary is updated. |
VoiceModelFile
Voice model file (.vvm file).
Methods
| Method | Description |
|---|---|
static open(string $path): self | Opens a .vvm file. |
id(): string | Returns the voice model ID as a hex string (16 bytes). |
createMetasJson(): string | Returns speaker metadata as a JSON string. |
close(): void | Closes the file and releases resources. |
Synthesizer
Main class for text-to-speech synthesis.
Methods
| Method | Description |
|---|---|
__construct(Onnxruntime $onnxruntime, OpenJtalk $openJtalk, AccelerationMode $accelerationMode = Auto, int $cpuNumThreads = 0) | Initializes the synthesizer. |
onnxruntime(): Onnxruntime | Returns the Onnxruntime instance held by this synthesizer. |
isGpuMode(): bool | Returns whether GPU mode is enabled. |
metas(): string | Returns metadata for all loaded speakers as a JSON string. |
loadVoiceModel(VoiceModelFile $model, OnExistingVoiceModelId $onExisting = Error): void | Loads a voice model. Use $onExisting to choose what happens when a model with the same ID is already loaded. |
unloadVoiceModel(string $voiceModelId): void | Unloads a voice model by its hex ID. |
isLoadedVoiceModel(string $voiceModelId): bool | Returns whether a voice model is loaded. |
createAudioQuery(string $text, int $styleId): string | Generates an AudioQuery JSON from Japanese text. |
createAudioQueryFromKana(string $kana, int $styleId): string | Generates an AudioQuery JSON from AquesTalk-style kana notation. |
createAccentPhrases(string $text, int $styleId): string | Generates an accent phrase array JSON from Japanese text. |
createAccentPhrasesFromKana(string $kana, int $styleId): string | Generates an accent phrase array JSON from kana notation. |
replaceMoraData(string $accentPhrasesJson, int $styleId): string | Returns updated accent phrases with mora pitch and phoneme length from another style. |
replacePhonemeLength(string $accentPhrasesJson, int $styleId): string | Returns updated accent phrases with phoneme lengths from another style. |
replaceMoraPitch(string $accentPhrasesJson, int $styleId): string | Returns updated accent phrases with mora pitch from another style. |
synthesis(string $audioQueryJson, int $styleId, bool $enableInterrogativeUpspeak = true): string | Synthesizes speech from an AudioQuery JSON. Returns WAV binary. |
createAudioFeature(string $audioQueryJson, int $styleId, bool $enableInterrogativeUpspeak = true): AudioFeature | Creates the AudioFeature intermediate representation used for frame-based rendering. |
tts(string $text, int $styleId, bool $enableInterrogativeUpspeak = true): string | Synthesizes speech from Japanese text in one step. Returns WAV binary. |
ttsFromKana(string $kana, int $styleId, bool $enableInterrogativeUpspeak = true): string | Synthesizes speech from kana notation. Returns WAV binary. |
createSingFrameAudioQuery(string $scoreJson, int $styleId): string | Generates a singing synthesis query JSON from a score JSON. |
frameSynthesis(string $frameAudioQueryJson, int $styleId): string | Synthesizes singing audio from a frame audio query. Returns WAV binary. |
createSingFrameF0(string $scoreJson, string $frameAudioQueryJson, int $styleId): string | Generates per-frame F0 (fundamental frequency) values as a JSON float array. |
createSingFrameVolume(string $scoreJson, string $frameAudioQueryJson, int $styleId): string | Generates per-frame volume values as a JSON float array. |
AudioFeature and AudioFeatureSlice
AudioFeature owns the native intermediate representation, and each AudioFeatureSlice keeps its owning AudioFeature alive. Rendering is synchronous and returns raw 16-bit PCM bytes.
| Class / method | Description |
|---|---|
AudioFeature::length(): int | Returns the total number of frames. |
AudioFeature::isEmpty(): bool | Returns whether the feature has no frames. |
AudioFeature::whole(): AudioFeatureSlice | Returns a slice covering the whole feature. |
AudioFeature::slice(int $startInclusive, int $end, bool $endIsInclusive = false, bool $clamp = false, bool $allowStartExceedsEnd = false): AudioFeatureSlice | Creates a frame-range slice. The end is exclusive by default. |
AudioFeature::render(): string | Renders the whole feature as PCM. |
AudioFeatureSlice::length(): int | Returns the number of frames in the slice. |
AudioFeatureSlice::isEmpty(): bool | Returns whether the slice has no frames. |
AudioFeatureSlice::slice(int $startInclusive, int $end, bool $endIsInclusive = false, bool $clamp = false, bool $allowStartExceedsEnd = false): AudioFeatureSlice | Creates a subslice using the same range options. |
AudioFeatureSlice::render(): string | Renders the slice as PCM. |
VoicevoxCore
Global utility functions for VOICEVOX Core.
Methods
| Method | Description |
|---|---|
getVersion(): string | Returns the VOICEVOX Core version as a SemVer string. |
getFrameRate(): float | Returns the number of audio frames per second (93.75 in CORE 0.17.1). |
audioQueryFrameLength(string $audioQueryJson, bool $enableInterrogativeUpspeak = true): int | Returns the estimated audio length in frames. |
audioQueryCreateFromAccentPhrases(string $accentPhrasesJson): string | Generates an AudioQuery JSON from an accent phrase array JSON. |
audioQueryValidate(string $audioQueryJson): void | Validates an AudioQuery JSON. Throws VoicevoxException if invalid. |
accentPhraseValidate(string $accentPhraseJson): void | Validates an AccentPhrase JSON. Throws VoicevoxException if invalid. |
moraValidate(string $moraJson): void | Validates a Mora JSON. Throws VoicevoxException if invalid. |
scoreValidate(string $scoreJson): void | Validates a Score JSON. Throws VoicevoxException if invalid. |
noteValidate(string $noteJson): void | Validates a Note JSON. Throws VoicevoxException if invalid. |
frameAudioQueryValidate(string $frameAudioQueryJson): void | Validates a FrameAudioQuery JSON. Throws VoicevoxException if invalid. |
framePhonemeValidate(string $framePhonemeJson): void | Validates a FramePhoneme JSON. Throws VoicevoxException if invalid. |
ensureCompatible(string $scoreJson, string $frameAudioQueryJson): void | Checks that a score and frame audio query are compatible. Throws VoicevoxException if not. |
UserDict
User dictionary for registering custom word pronunciations.
Methods
| Method | Description |
|---|---|
__construct() | Creates an empty user dictionary. |
load(string $path): void | Loads a user dictionary from a file. |
save(string $path): void | Saves the user dictionary to a file. |
addWord(string $surface, string $pronunciation, int $accentType, UserDictWordType $wordType = CommonNoun, int $priority = 5): string | Adds a word and returns its UUID as a hex string. |
updateWord(string $wordUuid, string $surface, string $pronunciation, int $accentType, UserDictWordType $wordType = CommonNoun, int $priority = 5): void | Updates an existing word identified by UUID. |
removeWord(string $wordUuid): void | Removes the word identified by UUID. |
importDict(UserDict $other): void | Imports words from another UserDict. |
toJson(): string | Returns all words as a JSON string. |
$priority must be between 0 and 10. Values outside that range throw an InvalidArgumentException.
Enum: AccelerationMode
Hardware acceleration mode for the synthesizer.
| Case | Value | Description |
|---|---|---|
Auto | 0 | Automatically selects the best available mode. |
Cpu | 1 | Forces CPU mode. |
Gpu | 2 | Forces GPU mode. |
Enum: OnExistingVoiceModelId
Behavior of Synthesizer::loadVoiceModel() when a voice model with the same ID is already loaded.
| Case | Value | Description |
|---|---|---|
Error | 0 | Throws an error. This is the default. |
Reload | 1 | Reloads the existing voice model. |
Skip | 2 | Does nothing. |
Enum: UserDictWordType
Part-of-speech for user dictionary entries.
| Case | Value | Description |
|---|---|---|
ProperNoun | 0 | Proper noun |
CommonNoun | 1 | Common noun |
Verb | 2 | Verb |
Adjective | 3 | Adjective |
Suffix | 4 | Suffix |