How to write the right thing, so put the text in "image_text.txt."



  • How to write the correct function: if the user makes this "Write File" team, the programme reads the image text and the entire text is placed in the "image_text.txt."

    I think I did something wrong, fix me.

    import pyttsx3
    import speech_recognition as sr
    import pytesseract
    pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract'
    from PIL import Image
    from pytesseract import image_to_string
    

    engine = pyttsx3.init()

    def sayToMe(talk):
    engine.say(talk)
    engine.runAndWait()

    sayToMe('Hello!')

    result = ''
    while result != 'exit':

    sayToMe('Com mand, please !')
    
    record = sr.Recognizer()
    try:
        with sr.Microphone(device_index=0) as source:
            print('Speak English, please! ...')
            audio = record. listen(source)
            result = record.recognize_google(audio, language="en—En")
            result = result.lower()
            print(result)
    
            if result == 'write file':
                text = image_to_string(Image.open('images/photo.png'))
                print(text)
                file = open('date/image_text.txt', 'w')
                file.write('text')
                file.close()
    
            elif result == 'read file':
                text = image_to_string(Image.open('image_text.txt'))
                print(text)
    
    except sr.UnknownValueError:
        print("Your speech is not recognized")
    except sr.RequestError:
        print("Something went wrong")
    



  • The mistake is, you're comparing the answer to the sound move with the words with the big letters, i.e., you take the answers to the bottom register, don't use the puncture.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2