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?

PythonでgTTSを使う

Last updated at Posted at 2025-09-27

gTTSとは

gTTSとはPythonですごく簡単に音声合成ができるモジュールです。

使ってみる

インストール

pip install gTTS

プログラム

まずは「こんにちは」という音声のデータを生成してみる。

#モジュールをインポート
from gtts import gTTS

# 読み上げたいテキストと、言語(日本語)を指定
text = 'こんにちは。'
tts = gTTS(text, lang='ja')

#音声データ'test.mp3'という名前で保存
tts.save('test.mp3')

音声を再生する

プログラム

このプログラムをさっきのプログラムに付け足してください。

# モジュールをインポート
import os

Windowsの場合

# 保存した音声を再生
os.startfile('test.mp3')

macOSの場合

# 保存した音声を再生
os.system('open ' + 'test.mp3')

Linuxの場合

# 保存した音声を再生
os.system('xdg-open test.mp3')

速さを変更する

音声のスピードを変える機能を使ってみます。

プログラム

早くする

#7行目をこのプログラムに変更
tts = gTTS(text=text, lang="ja", slow=False)

遅くする

#7行目をこのプログラムに変更
tts = gTTS(text=text, lang="ja", slow=True)
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?