Last active
October 9, 2023 11:42
-
-
Save tam17aki/d5549922cb17d8038b6849176f5d7e25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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