Package voicevox

voicevox client for python.

:target: https://voicevox-client.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

Unoffical API wrapper that you can use voicevox easy!

Requirements

Voicevox engine only!

Well if you want install voicevox engine, please read this <https://github.com/VOICEVOX/voicevox_engine/blob/master/README.md>__.

Install

Code: sh

pip install voicevox-client

All that!

Example

Code: python

from voicevox import Client import asyncio

async def main(): async with Client() as client: audio_query = await client.create_audio_query( "こんにちは!", style_id=1 ) with open("voice.wav", "wb") as f: f.write(await audio_query.synthesis(style_id=1))

if name == "main": ## already in asyncio (in a Jupyter notebook, for example) # await main() ## otherwise asyncio.run(main())

Sub-modules

voicevox.audio_query
voicevox.client
voicevox.errors
voicevox.http
voicevox.speaker_info
voicevox.speakers
voicevox.supported_devices
voicevox.types

Classes

class AudioQuery (http: HttpClient, payload: AudioQueryType)

Audio query

Audio query to do synthesis.

Attributes

accent_phrases : dict
アクセント句のリスト
speed_scale : float
Speech speed
pitch_scale : float
Speech pitch
intonation_scale : float
Speech intonation
volume_scale : float
Speech volume
pre_phoneme_length : float
音声の前の無音時間
post_phoneme_length : float
音声の後の無音時間
output_sampling_rate : int
音声データの出力サンプリングレート
output_stereo : bool
音声データをステレオ出力するか否か
kana : str
[読み取り専用]AquesTalkライクな読み仮名。音声合成クエリとしては無視される

Instance variables

var kana : str

Methods

async def synthesis(self, *, enable_interrogative_upspeak: bool = True, speaker: int, core_version: Optional[str] = None) ‑> bytes
def to_dict(self) ‑> AudioQueryType
class Client (base_url: str = 'http://localhost:50021', timeout: Optional[int] = None)

Voicevox client class

Wrap voicevox engine api.

Parameters

base_url : str
Voicevox engine endpoint uri.

Attributes

http : HttpClient
Http client attribute.
timeout : Optional[int]
You can customize timeout. If you use cpu mode, I recommend to use this.

Methods

async def check_devices(self, core_version: Optional[str] = None) ‑> SupportedDevices
async def check_inited_speaker(self, speaker: int, *, core_version: Optional[str] = None)

Check initialized speaker

Returns whether the speaker with the specified speaker_id is initialized or not.

Parameters

speaker : int
speaker id
core_version : Optional[str]
core version

Returns

bool
If initialized speaker, it return True.
async def close(self) ‑> None

Close http client

You must run this function, when you finish process.

async def create_audio_query(self, text: str, speaker: int, *, core_version: Optional[str] = None) ‑> AudioQuery

Create audio query

If you want do tts, you must run first.

Parameters

text : str
Text message
style_id : int
Speaker id
core_version : str
Core version

Returns

AudioQuery
Audio query, that run synthesis.
async def create_audio_query_from_preset(self, text: str, preset_id: int, *, core_version: Optional[str] = None) ‑> AudioQuery
async def fetch_core_versions(self) ‑> List[str]

Fetch core versions

This can fetch voicevox core versions.

Returns

List[str]
Core versions
async def fetch_engine_version(self) ‑> str

Fetch engine version

This can fetch voicevox engine version.

Returns

str
Engine version
async def fetch_speaker_info(self, speaker_uuid: str, core_version: Optional[str] = None) ‑> SpeakerInfo

Fetch speaker's info by given uuid.

This function retrieves additional information about a specific speaker, including its voice samples, icon, and portrait images.

Parameters

speaker_uuid : str
speaker's uuid
core_version : Optional[str]
voicevox core version

Returns

SpeakerInfo
Contains additional information of the speaker.
async def fetch_speakers(self, core_version: Optional[str] = None) ‑> List[Speaker]

Fetch speakers

This can fetch voicevox speakers.

Returns

List[Speaker]
Speakers
async def init_speaker(self, speaker: int, *, skip_reinit: bool = False, core_version: Optional[str] = None) ‑> None

Initilize speaker

Initializes the speaker with the specified speaker_id. Other APIs can be used without executing this function, but it may take some time when it is executed for the first time.

Parameters

speaker : int
speaker id
skip_reinit : bool
Whether to skip reinitialization of speakers who have already been initialized
core_version : Optional[str]
core version
async def multi_synthesis(self, audio_queries: List[AudioQuery], speaker: int, *, core_version: Optional[str] = None) ‑> bytes

Multi synthe

This function is like AudioQuery.synthesis, but it can synthesis multi!

Parameters

audio_queries : List[AudioQuery]
Array of audio query
speaker : int
speaker id
core_version : Optional[str]
voicevox core version

Returns

bytes
Return zip file
class HttpException (*args, **kwargs)

Common base class for all non-exit exceptions.

Ancestors

  • builtins.Exception
  • builtins.BaseException

Subclasses

class NotfoundError (*args, **kwargs)

Common base class for all non-exit exceptions.

Ancestors

class Speaker (payload: SpeakerType)

Return speaker info

Attributes

supported_features : SupportedFeature
return supported_features
name : str
speaker name
uuid : str
speaker uuid
version : str
speaker version
styles : List[Style]
speaker styles
class Style (payload: StyleType)

Return style info

Attributes

name : str
style name
id : int
style id

Instance variables

var id : int
var name : str
class SupportedFeature (payload: SupportedFeatureType)

Return supported feature info

Attributes

permitted_synthesis_morphing : str
return permitted_synthesis_morphing