通过语音识别创建文件

时间:2020-06-07 17:57:31

标签: python speech-recognition tk

我想通过语音识别创建文件,并通过SR创建文件。问题是它仅在我关闭程序时创建或删除文件。

我想在程序运行时而不是之后创建文件。所以请,有人可以帮忙吗?

这是我的代码:

def createfile():
    with sr.Microphone() as source:
        print("Speak now")
        audio = mic1.listen(source)

    cmd = mic2.recognize_google(audio)  # convert audio into string
    print(mic2.recognize_google(audio))
    create_UC(cmd)


def create_UC(cmd):
    if "create" in cmd.lower():
        fileName = fileName + ".txt"
        print(fileName)
        if os.path.exists(not fileName):
            f = open(fileName, 'w+')
            f.close()
        else:
            showinfo("Error", "Sorry, File Already Exist!")

0 个答案:

没有答案