🙄

【Azure AI Speech】- .wavの音声ファイルの作成方法について

2025/03/04に公開

執筆日

2025/3/4

やること

Azure AI Speechを使って、.wav形式のファイルとして保存する。

前提

  • Azure AI Speechをデプロイ済みであること。
  • Azure AI Speechのキーとリージョンを取得していること。

ライブラリーのインストール

pip install azure-cognitiveservices-speech

コード

import azure.cognitiveservices.speech as speechsdk

speech_key = <"Azure Speechキー">
service_region = <"Azure Speech のデプロイリージョン">  # 例:"eastus", "japaneast" など

# Speech設定
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

# 出力形式を.wavに指定
audio_config = speechsdk.audio.AudioOutputConfig(filename="output.wav")

# 言語や音声の種類を指定(日本語の例)
speech_config.speech_synthesis_voice_name = "ja-JP-NanamiNeural"

# 音声合成の実行
synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)

text = "こんにちは、Azureの音声合成です。"
result = synthesizer.speak_text_async(text).get()

# 結果を確認
if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
    print("音声の合成が完了し、output.wav に保存されました。")
else:
    print(f"音声の合成に失敗しました: {result.reason}")

補足

音声の種類について

日本語は以下に対応しています。

ja-JP-NanamiNeural (女性)
ja-JP-KeitaNeural (男性)
ja-JP-AoiNeural (女性)
ja-JP-DaichiNeural (男性)
ja-JP-MayuNeural (女性)
ja-JP-NaokiNeural (男性)
ja-JP-ShioriNeural (女性)
ja-JP-MasaruMultilingualNeural (男性)
ja-JP-Masaru:DragonHDLatestNeural (男性)
ja-JP-Nanami:DragonHDLatestNeural (女性)

https://learn.microsoft.com/ja-jp/azure/ai-services/speech-service/language-support?tabs=stt#text-to-speech

出力音声の仕様

デフォルトではPCM 16-bit、16kHz、モノラルの.wav形式で音声が生成されます。

ヘッドウォータース

Discussion