💨

宮舞モカをPythonでいじる

に公開

コマンドラインから引数を投げるだけなんで、Pythonである必要はないんですけどね。
参考にしたのはこちらのページです。
https://atarms.hatenablog.com/entry/2023/03/12/164118


https://amzn.to/47ALUP1

import os
import subprocess
import winsound

default_emotions = {
    "bosoboso":15, 
    "doyaru":30, 
    "honwaka":15, 
    "angry":0, 
    "teary":0
}

script = """
こんにちは、宮舞モカです。
この部分の内容を書き換えることで、しゃべる内容を変更することができます。
一度の読み上げで140文字まで対応しています。なんだかXみたいですね。
長い文章を読み上げる場合は分割して渡す必要があるので注意です。
"""


def playVoicePeak(script , narrator = "Miyamai Moca", emotions={}, filename="output.wav", delete_after_play=True):
    """
    任意のテキストをVOICEPEAKのナレーターに読み上げさせる関数
    """
    # voicepeak.exeのパス
    exepath = "C:/Program Files/VOICEPEAK/voicepeak.exe"

    # 感情
    if emotions == {}:
        emotions = default_emotions
    emotions_str = ",".join([f"{key}={value}" for key, value in emotions.items()])
    # 引数を作成
    args = [
        exepath,
        # "--list-narrator", # ナレーターのリストを取得
        # "--list-emotion", narrator, # ナレーターの感情リストを取得
        "-n", narrator,
        "-s", script,
        "-o", filename,
        "-e", emotions_str
    ]

    
    # プロセスを実行
    process = subprocess.Popen(args)

    # プロセスが終了するまで待機
    process.communicate()

    # 音声を再生
    winsound.PlaySound(filename, winsound.SND_FILENAME)

    # wavファイルを削除
    if delete_after_play and os.path.exists(filename):
        os.remove(filename)

# 実行部分
playVoicePeak(script)

https://amzn.to/47ALUP1

Discussion