1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Excel VBA(マクロ)でセルの内容を声を変えて読上げ -その1-Harukaの声以外を使って読上げる

Last updated at Posted at 2023-05-01

Excel VBA(マクロ)でセルの内容を読上げ-その1

動画にナレーションを入れるのに、無料の音声合成を使っていました。

ただ、いろいろな制約で、オンラインでの音声合成は不可。
無料ソフトでも、Admin権限を持たせてもらえないので、インストールも不自由。

したがって、
Balabolkaのポータブル
を使っていました。
かなり、使えるソフトなのですが、Windowsの標準で入っているHarukaしか選択できないのが不満。
Windows標準機能のナレータでは、Ayumi、Sayaka、Ichiroも選択できるのに。

Excel2019が入っているPCなので、Excel VBA(マクロ)で、可能にする様にしました。

声を選択できるようにする

以下の設定で、声を変数に入れます。

    '声を入れるためのオブジェクト変数
    Dim HarukaVoice, AyumiVoice, SayakaVoice, IchiroVoice, ZirVoice As Object
    'SpeechAPIのSpVoiceおよびSpObjectTokenCategoryの変数
    Dim sapi, cat As Object

Private Sub voice_object()
    'SpeechAPIの設定
    Set sapi = CreateObject("SAPI.SpVoice")
    '読み手の分類設定
    Set cat = CreateObject("SAPI.SpObjectTokenCategory")
    '分類の参照先をSpeechフォルダからSpeech_OneCoreに変更
    cat.SetID "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices", False
    '読み手の名前を参照し、オブジェクト変数に収容
    For Each token In cat.EnumerateTokens
        'はるか
        If token.GetAttribute("Name") = "Microsoft Haruka" Then Set HarukaVoice = token
        'あゆみ
        If token.GetAttribute("Name") = "Microsoft Ayumi" Then Set AyumiVoice = token
        'さやか
        If token.GetAttribute("Name") = "Microsoft Sayaka" Then Set SayakaVoice = token
        '一郎
        If token.GetAttribute("Name") = "Microsoft Ichiro" Then Set IchiroVoice = token
    Next
    '英語のZirは、Speech_OneCoreに無いので、Speechの中の英語(409)を指定
    Set zirVoice = spi.GetVoices("language=409")(0)
    Set cat = Nothing
    Set sapi = Nothing
End Sub

これで、 voice_object をCallすることで、声を選択できます。

使い方:

Sub 読上げ()
    '話し手の設定
    Call voice_object
    '音声合成エンジン設定
    Set spai = CreateObject("SAPI.SpVoice")
    '読み手 一郎
    Set sapi.Voice = IchiroVoice
    '現在地の内容を読上げ
    sapi.Speak ActiveCell

    Set sapi = Nothing
End Sub

Balabolkaのポータブル
で可能だった、読上げスピードやピッチ(声の高低調整)をすることも可能です。
TTS(Text To Speech)で基準となっている内容で、前後に「<Rate speed=""> </Rate>」
「<Pitch middle=""> </pitch>」を置くことで調整可能です。
speed, middleの後の「””」の中には、-10~10の値が入ります。0が標準。

    '現在地の内容を読上げ
    sapi.Speak "<Rate speed="3"><Pitch middle="-5">" & ActiveCell & "</Pitch></Rate>"

とすることで、速さが+3され、ピッチが5 低くなります。
ちなみに、ピッチについては、24で1オクターブ上下する規格になっています。
±10しか許されていませんが。

その2 -読上げ内容を音声ファイルに保存する- へ続く

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?