<gh_stars>1-10
"""Using a speech engine to highlight words
http://www.rosettacode.org/wiki/Using_a_speech_engine_to_highlight_words
"""

import pyttsx3


def main():
    # initialize tts engine
    engine = pyttsx3.init()
    engine.setProperty("rate", 200)
    engine.setProperty("volume", 1.0)

    # set voice type and language installed in system
    print("Select speech engine to use:")
    voices = engine.getProperty("voices")
    for idx, properties in enumerate(voices):
        print(f" [{idx}] {properties.name}")
    voice_num = int(input("Select num: "))
    engine.setProperty("voice", voices[voice_num].id)

    # set text and speak
    phase = "This is an example of speech synthesis."
    print(phase)
    engine.say(phase)
    engine.runAndWait()

    for word in phase.split():
        print(word, end=" ")
        engine.say(word)
        engine.runAndWait()
    print()
    engine.stop()


if __name__ == "__main__":
    main()
