1

I want to create a file by speech Recognition and create file by SR. The problem is it only creates or delete file when I close the program.

I want to create my files while program is running, not after that. So please, can someone help?

This is my code:

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!")
Barbora
  • 921
  • 1
  • 6
  • 11
Burair abbas
  • 77
  • 1
  • 7
  • see the discussion under https://stackoverflow.com/questions/2967194/open-in-python-does-not-create-a-file-if-it-doesnt-exist – dr_agon Jun 07 '20 at 19:41
  • 1
    you must correct `if os.path.exists(not fileName):` to `if not os.path.exists(fileName):` – dr_agon Jun 07 '20 at 19:46
  • that link doesn't have my answer i already used 'w+' !! and thanks for code correctness. – Burair abbas Jun 08 '20 at 04:40
  • how do you check if the file was created? Are you sure it is not a system caching problem? – dr_agon Jun 08 '20 at 05:52
  • i am sorry but i have no idea wht the system caching problem is!! seen like my problem is solve i have to submit my assignment today! Thanks u for helping me! – Burair abbas Jun 08 '20 at 06:52

0 Answers0