Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将函数的参数转换为字符串_Python_Python 3.x_Speech Recognition_Google Text To Speech_Gtts - Fatal编程技术网

Python 如何将函数的参数转换为字符串

Python 如何将函数的参数转换为字符串,python,python-3.x,speech-recognition,google-text-to-speech,gtts,Python,Python 3.x,Speech Recognition,Google Text To Speech,Gtts,我正在制作一个聊天机器人,我试图创建一个函数来获取问题并以某种方式进行响应,但我收到一个错误,上面写着TypeError:type'function'的参数是不合适的关于“def quanda”部分中的if语句,我如何解决这个问题 import os import speech_recognition as sr from gtts import gTTS import playsound import time def speak(text): tts = gTTS(text=te

我正在制作一个聊天机器人,我试图创建一个函数来获取问题并以某种方式进行响应,但我收到一个错误,上面写着
TypeError:type'function'的参数是不合适的
关于“def quanda”部分中的if语句,我如何解决这个问题

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


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

def qanda(question, response):
    text = get_audio
    if question in text:
        speak(response)
    return response

speak("hello, how can i help you?")

text = get_audio

qanda("hello", "hi there")

quanda("what is the weather", "Its 27 degrees")

这是因为
get\u audio
是一种方法,您需要使用
()
调用它。因此,无论您在哪里调用
get\u audio
方法,都可以这样调用它:
get\u audio()

这是因为
get\u audio
是一个方法,您需要使用
()
调用它。因此,无论您在何处调用
get\u audio
方法,都可以这样调用:
get\u audio()

您已经在向函数传递字符串,如果必须将对象转换为字符串,则应使用
str
-
str(问题)
您已经向函数传递字符串的可能重复项,如果必须将对象转换为字符串,则应使用
str
-
str(问题)
的可能重复项