0

I am writing code for voice recognition I am run the program, I am getting TypeError problem.

This is my code:

import pyttsx3 
import pyaudio 
import speech_recognition as sr
import webbrowser
import datetime
import pyjokes
​
def sptext():
    recognizer=sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening....")
        recognizer.adjust_for_ambient_noise(source)
        audio = recognizer.listen(source)
        try:
            print("recognizing...")
            data = recognizer.recognize_google(audio)
            print(data)
        except sr.UnknownValueError:
            print("Not understanding")
def speechtxt():
    engine = pyttsx3.init()
    voices = engine.getProperty("voices")
    engine.setProperty("voice",voices[0].id)
    rate=engine.getProperty('rate')
    engine.setProperty('rate',150)
    engine.say(x)
    engine.runAndWait()
speechtxt("hello")

Output (error):

TypeError                                 Traceback (most recent call last)
Input In [32], in <cell line: 28>()
     26     engine.say(x)
     27     engine.runAndWait()
---> 28 speechtxt("hello")

TypeError: speechtxt() takes 0 positional arguments but 1 was given

How can I solve this error?

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

You aren't accepting any parameters in your speechtxt function, so when you try to pass one in, it errors out.

From the rest of your code, it looks like you want to replace:

def speechtxt():

with:

def speechtxt(x):

so that way it accepts the one parameter, x.

rtuna
  • 67
  • 6