Search code examples
pythonraspberry-pipyttsx

Making a talking list for a vending machine, using python and pyttsx3. How to go back forth through a list?


I going to use a raspberry pi4 with three buttons, 'back', 'repeat', 'next'.

So far, with pyttsx3, I have defined a function for number 66 in the vending machine like so:

def no66():
    engine.say("Mrs Freshlys Cupcakes, 66")
    engine.runAndWait()

If I want to make a list of all the things in the vending machine, is it ok to continue to define functions for each number? and How do I map them to the buttons so blind people can go manually back and forth through the list or repeat one entry?

We want to attach the rasberry pi with the three buttons next to the vending machine (which already has braille on the keypads), so its easier for people to use. like a vending machine catalogue of sorts.


Solution

  • Please note my comment, in the future please try to break down your problem as far as possible and ask single, specific questions.

    Since it is relatively easy, I will hint you in a possible direction:

    1. Make a list of all your items:

      my_items = ["Soup", "Stew", "Soda"]
      
    2. Save the current selection as a state:

      current_item = 1 # Represents the position in the list, 1 is Stew
      
    3. create a generic read function:

      def read(id):
          item_name = my_items[id]
          engine.say(item_name + ", Nr." + id)
          engine.runAndWait()
      
    4. Your buttons simply modify this item, and then call a generic read function

      def go_forward():
          current_item = current_item + 1 # Also think about edge cases at the end of the list!
          read(current_item)
      

    This is a rough draft to point you in the right direction.