Wie kann ich in Python einen Loop einfügen der aus einer Exceltabelle ausliest?

Hallo würde mir gerne meine Vokalen mit Text to Speech vorlesen lassen, ich habe dafür eine Excel-Tabelle mit Englischen und Deutschen Vokabeln.

Mein Problem ist das ich nicht weiß wie man in Python eine automatische loop einfügt die dann von einem English/Deutschvokabel Paar zum nächsten geht und sie vorliest.

Weil so wie ich es jetzt habe muss ich bei jedem neuen Vokabel paar eine manuelle Variable erstellen und dann diese wieder in meinen Text to Speech Code einfügen.

Mein Code:

import openpyxl
import pyttsx3


# Give the location of the file
path = "test.xlsx"

# To open the workbook
# workbook object is created
wb_obj = openpyxl.load_workbook(path)

# Get workbook active sheet object
# from the active attribute
sheet = wb_obj.active

# Cell objects also have a row, column,
# and coordinate attributes that provide
# location information for the cell.

# Note: The first row or
# column integer is 1, not 0.

# Cell object is created by using
# sheet object's cell() method.
wort1en = sheet.cell(row=1, column=1)
wort1de = sheet.cell(row=1, column=2)


# Text to Speech
engine = pyttsx3.init()

# Voice IDs pulled from engine.getProperty('voices')
# These will be system specific
de_voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_DE-DE_HEDDA_11.0"
en_voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0"

# Set properties _before_ you add things to say
engine.setProperty('rate', 160)    # Speed percent (can go over 100)
engine.setProperty('volume', 1)  # Volume 0-1
# Use female English voice
engine.setProperty('voice', en_voice_id)
engine.say(wort1en.value)


# Set properties _before_ you add things to say
engine.setProperty('rate', 150)    # Speed percent (can go over 100)
engine.setProperty('volume', 0.9)  # Volume 0-1
# Use female German voice
engine.setProperty('voice', de_voice_id)
engine.say(wort1de.value)


engine.runAndWait()

Meine Vokabelliste:

Bild zum Beitrag
Computer, programmieren, Informatik, Python

Meistgelesene Beiträge zum Thema Python