Не работает модуль «pyttsx3» для озвучивания текста
Вы используете устаревший браузер. Этот и другие сайты могут отображаться в нем неправильно.
Необходимо обновить браузер или попробовать использовать другой.
Samylov_2008
Новичок
Пользователь
Июн 1, 2020 7 0 1
Операционная система «Windows», «Python 3.8».
"""Импортируем модуль""" import pyttsx3 """Инитизируем""" engine = pyttsx3.init () """Спрашиваем какой текст озвучить, ответ записывает в переменную text""" text = str (input ("Какой текст озвучить? ")) """Озвучиваем""" engine.say (text) engine.ranAndWait ()
Код озвучивает текст, который написал пользователь.
При запуске программы пишет большую ошибку:
Traceback (most recent call last):
File «C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py», line 20, in init
eng = _activeEngines[driverName]
File «C:\Users\User\AppData\Local\Programs\Python\Python38\lib\weakref.py», line 131, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File «D:/Программы Pyton/Помошник/ghbdtn.py», line 4, in
engine = pyttsx3.init ()
File «C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py», line 22, in init
eng = Engine(driverName, debug)
File «C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\engine.py», line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File «C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\driver.py», line 50, in __init__
self._module = importlib.import_module(name)
File «C:\Users\User\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py», line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File «», line 1014, in _gcd_import
File «», line 991, in _find_and_load
File «», line 975, in _find_and_load_unlocked
File «», line 671, in _load_unlocked
File «», line 783, in exec_module
File «», line 219, in _call_with_frames_removed
File «C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py», line 10, in
import pythoncom
ModuleNotFoundError: No module named ‘pythoncom’
Как я понял, типа в этом модуле есть ещё модуль «pythoncom» . Который он не находит — No module named ‘pythoncom’ . Я его в интернете не нашёл.
Помогите пожалуйста, я новичок. Заранее спасибо!
Convert Text to Speech in Python
- Use the gTTS Module to Convert Text to Speech in Python
- Use the pyttsx3 Module to Convert Text to Speech in Python
Due to the advancement in technology over the past few decades, we have many devices equipped with speech recognition. Python has a wide variety of modules available which can work with audio objects. Some modules can convert some written text to audio.
In this tutorial, we will discuss how to convert text to speech using Python.
Use the gTTS Module to Convert Text to Speech in Python
Google created an API called Google Text-To-Speech which they use to read a text and give audio output. This API is integrated with a Python module called gtts , which can convert text to speech, perform audio manipulation, among other things, by storing audio in a byte-sized object, and even save the final output.
We will use the gTTS function to create an object which will read the text and convert it to an audio object. We can use many parameters with this function. We can reduce the speed of the output using the slow argument. The Google API supports different languages, and we can mention supported languages using the lang parameter.
We will implement this method in the following code.
from gtts import gTTS from playsound import playsound s = gTTS("Sample Text") s.save("sample.mp3") playsound("sample.mp3")
In the above code, we create an object which reads the desired text. We save this object containing the speech audio using the save() function and then play it using the playsound() function. The playsound() function imported from the playsound library can play an audio file.
Note that given this module uses the Google API to convert text to speech, it will require an active internet connection. You can consider the method discussed below if you want it to run offline.
Use the pyttsx3 Module to Convert Text to Speech in Python
The pyttsx3 is another module that can perform such conversions and work without an internet connection. First, we will create an object which references the pyttsx3.Engine using the init() constructor from this module. Then the say() function here adds the required text to be spoken in the queue. Then we use the runAndWait() function to play the command from the queue.
import pyttsx3 s = pyttsx3.init() data = "Sample Text" s.say(data) s.runAndWait()
We can set the properties like the playback rate of the final output using the setProperty() method. This module is compatible with Python 2 and Python 3.
Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.
Related Article — Python Audio
- Play Mp3 File Using Python
- Real-Time Audio Processing in Python
- Python Audio Synthesis
- Convert MP3 to WAV in Python
Какой модуль использовать для преоброзавания текста в речь?

Сам недавно столкнулся с таким же вопросом, загуглив получилось решить минут за 20. Просто используйте yandex speachkit. Есть 1 и 3 на счёт 2 пункта не знаю, не разбирался, да и там можно выбрать каким голосом озвучивать.
Ответ написан более трёх лет назад
Комментировать
Нравится Комментировать
Ответы на вопрос 0
Ваш ответ на вопрос
Войдите, чтобы написать ответ

- Python
Как сгенерировать случайное имя файла?
- 1 подписчик
- час назад
- 45 просмотров

- Python
Когда запускаю клиента вылетает из всех устройств?
- 1 подписчик
- 6 часов назад
- 43 просмотра
Голосовая озвучка текста
Озвучка текста — нейросеть
Доброго дня, друзья! Подскажите, пожалуйста. Есть ли нейросеть или сервис, которые могут бесплатно.
Озвучка русского текста
Добрый день. Подскажите пожалуйста по следующему вопросу. Требуется озвучить русский текст.
Озвучка текста сайта. JavaScript
Здравствуйте. Есть задание: дополнить сайт озвучкой текста при помощи js. И вроде бы лекция дана, и.
Озвучка текста сайта. JavaScript
Здравствуйте. Есть задание: дополнить сайт озвучкой текста при помощи js. И вроде бы лекция дана, и.
озвучка клавиатуры
написал такую программу, озвучивание клавиш masm .model small .stack 256 .data .
