0

I am trying to make a Voice assistant in python using this code

import os
from gtts import gTTs
import time
import playsound
import speech_recognition as sr



def speak(text):
    tts = gTTS(text=text, lang="en")
    filename = "voice.mp3"
    tts.save(filename)
    playsound.playsound(filename)

def get_audio():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        audio = r.listen(source)
        said = ""

        try:
            said = r.recognize_google(audio)
            print(said)
        except Exception as e:
            print("Exception: " + str(e))

    return said


text = get_audio()

if "who are you" in text:
    speak(" I am Friday the virtual assistant")

And when i run it, it shows this error ImportError: cannot import name gTTS

Any help would be amazing :)

Edit:I have changed it to gTTS and still get ImportError: cannot import name gTTS

qwertyboy2020
  • 11
  • 1
  • 2

4 Answers4

3

Try replacing

from gtts import gTTs

with

from gtts import gTTS

(Note the capital S)

Jasmijn
  • 9,370
  • 2
  • 29
  • 43
1

I also got this problem once because i named my python file as gtts.py so i changed the name of the file to something else and it stopped giving error.

0

First you have to install the gtts module with this command by going to the terminal and type following line:

pip install gTTS

After you install this, import like this:

from gtts import gTTS
0

I got the same error. Just make sure you are using the right python Interpreter.