Skip to content

Instantly share code, notes, and snippets.

@tam17aki
Last active October 9, 2023 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tam17aki/d5549922cb17d8038b6849176f5d7e25 to your computer and use it in GitHub Desktop.
Save tam17aki/d5549922cb17d8038b6849176f5d7e25 to your computer and use it in GitHub Desktop.
from pathlib import Path
from voicevox_core import AccelerationMode, VoicevoxCore
import sounddevice as sd
import soundfile as sf
SPEAKER_ID = 2 # 話者IDを指定
open_jtalk_dict_dir = './open_jtalk_dic_utf_8-1.11'
text = 'これは音声合成のデモンストレーションです。'
OUTPUT_WAV = 'output.wav'
out = Path(OUTPUT_WAV)
acceleration_mode = AccelerationMode.AUTO
def main():
core = VoicevoxCore(
acceleration_mode=acceleration_mode, open_jtalk_dict_dir=open_jtalk_dict_dir
)
core.load_model(SPEAKER_ID) # 話者IDを指定してモデルをロード
audio_query = core.audio_query(text, SPEAKER_ID)
wav = core.synthesis(audio_query, SPEAKER_ID) # 音声合成を実行
out.write_bytes(wav) # 合成結果をwavに保存する
# 合成結果のwavを再生する
data, fs = sf.read(OUTPUT_WAV, dtype='float32')
sd.play(data, fs) # 再生
sd.wait() # 再生完了まで待機(この命令は必須!)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment