8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenAI の Text to speech API を試してみた。

Last updated at Posted at 2025-05-15

OpenAI から Text to speech API がリリースされていたので、試しに音声ファイルを出力してみました。

コード

API キーは、OpenAI のアカウントで作成してください。
ChatGPT の API キーをお持ちの方は、まんま流用することもできます。

import openai

# OpenAI API キーを設定
openai.api_key = "<OpenAI API キー>"

# 音声生成リクエスト
response = openai.audio.speech.create(
	model = "tts-1",
	voice = "alloy",
	input = "Hello, how are you?"
)

# 音声ファイルとして保存
with open( "output.mp3", "wb" ) as file:
	file.write( response.content )

パラメータ

  • model
    • 音声合成モデル
      • "tts-1"
      • "tts-1-hd"
  • voice
    • ボイス
      • 男性
        • "alloy"
        • "ash"
        • "echo"
        • "fable"
        • "onyx"
      • 女性
        • "coral"
        • "nova"
        • "sage"
        • "shimmer"
  • input
    • 読み上げるテキスト
      • 日本語も対応しているようです。

参考サイト

(2025/04 頃執筆)


株式会社ボトルキューブではお仕事を募集中です。
お問い合わせは下記リンク先のフォームからご連絡ください。
https://www.bottlecube.co.jp/contact

8
4
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
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?