Python показывает ошибку «Нет модуля с именем gTTS». - PullRequest
0 голосов
/ 08 января 2020

Я хотел создать python код для Voice Assistance, который будет использовать gTTS. Я запустил код, но он не работал, как он мне показал,

Трассировка (последний последний вызов):

File "/Users/niallquadros/Desktop/voiceassistant.py ", строка 1, в <module> из gTTS import gTTS

ModuleNotFoundError: Нет модуля с именем 'gTTS'

Вместо этого он должен был дать мне результат и действовать как голосовой помощник.

Это был мой код, который я написал на MacBook Air 2019 на python (3.7.4)

from gTTS import gTTS
import speech_recognition as sr
import os
import webbrowser
import satplib

def talkToMe(audio):
    print (audio)
    tts = gTTs(text=audio, lang='en')
    tts.save('audio.mp3')
    os.system('mpg123 audio.mp3')

#Listen for commands
def myCommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('I am ready for your next command')
        r.pause_threshold = 1
        r.adjust_for_ambient_noise(source, duration = 1)
        audio = r.listen(source)

    try:
        command = r.recognize_google(audio)
        print('You said: ' + command + '/n')

    #loop back to continue to listen for commands

    except sr.UnknownValueError:
        assistant(myCommand())

    return command

#if statesments for executing commands
def assistant(command):

    if 'open Reddit python' in command:
        chrome_path = '/user/bin/google.chrome'
        url = 'https://www.reddit.com/r/python'
        webbrowser.get(chrome_path).open(url)

    if 'what\'s up' in command:
        talkToMe('Chillin Bro')

while True:
    assistant(myCommand()) 

В моем терминале он показывает, что у меня есть gtts уже установлен.

(base) Nialls-MacBook-Air:~ niallquadros$ pip search gTTS
gTTS (2.1.0)        - gTTS (Google Text-to-Speech), a Python library and CLI
                      tool to interface with Google Translate text-to-speech
                      API
  INSTALLED: 2.1.0 (latest)
Django-Gtts (0.2)   - gTTS google text-to-speech django app
Flask-gTTS (0.12)   - gTTS Google text to speech flask extension
gTTS-token (1.1.3)  - Calculates a token to run the Google Translate text to
                      speech
  INSTALLED: 1.1.3 (latest)
wired-tts (0.2.0)   - "gTTS based Wired story reader."

Что делать, чтобы я мог выполнить код?

Ответы [ 3 ]

1 голос
/ 09 января 2020

Попробуйте это:

from gtts import gTTS
1 голос
/ 15 апреля 2020

Попробуйте:

from gtts import *

Это будет импортировать все. Это сработало для меня.

0 голосов
/ 09 января 2020

Введите следующую команду:

из gtts import gTTS

вместо: из gTTS import gTTS

...