LoginSignup
0
0

Pythonのpyttsx3のNameErrorの対処

Posted at

音声読み上げてくれるアプリを作りたかったので調べる。

↑これを参考にしてpyttsx3モジュールを使い音声を読み上げさせる。

import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
NameError: name 'objc' is not defined

オブジェクトが見つからないので調べる。

解決

参考

「py3-tts のインストールに従ったところ、ダミーパラメータなしで動作するようになりました。」
と記載してあったのでpy3-ttsをダウンロード。

$ pip install py3-tts

無事音声が使えるようになりました!!

なぜ使えるようになったか?公式の説明を見てみると...

pyttsx3 2.90
Python 2 および 3 用の Text to Speech (TTS) ライブラリ。インターネット接続や遅延なしで動作します。 Sapi5、nsss、espeak などの複数の TTS エンジンをサポートします

py3-tts 3.5
Python 3 の Text to Speech (TTS) ライブラリ。インターネット接続や遅延なしで動作します。 Sapi5、nsss、espeak などの複数の TTS エンジンをサポートします

自分のインストールしたpyttsx3がpython3.8には対応していなかったことが原因?

0
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
0
0