-3

プログラミングの学習を始めたばかりで、簡単なチャットボット コードに手を出し始めました。テキストで応答がありますが、コンピューター (Mac) で応答を読み上げ、表示と同時に応答のみを読み上げたいです。コードは次のとおりです。

import random 

import sys

import os

def show_response(options):

choice = random.randint(0, len(options) -1)

print(options[choice])

random.seed(None)

while True:
    userInput = input(">>>")

    if userInput in ["Ava, you there?"]:
        list = ["Indeed I am, Sir.", "Yes, Sir. What do you need?", "For you, Sir, always.", "I am now.", "What is it, Sir?", "I'm right here.", "How may I assist you, Sir?", "How may I assist you?", "You need something, Sir?"]
        choice = random.randint(0, len(list) -1)
        print(list[choice])
    elif userInput in ["Wake up, Ava"]:
        list = ["What is it, Sir?", "How can I help?", "How can I help, Sir?", "Hello, Sir.", "Hello, Sir. Is there anything you need?", "How may I assist you?", "How may I assist you, Sir?"]
        choice = random.randint(0, len(list) -1)
        print(list[choice])
    elif userInput in ["Hey, Ava"]:
        list = ["What is it, Sir?", "How can I help?", "How can I help, Sir?", "Hello, Sir.", "Hello, Sir. Need anything?", "How may I assist you?", "How may I assist you, Sir?", "You need something, Sir?"]
        choice = random.randint(0, len(list) -1)
        print(list[choice])

これが繰り返しである場合は、お詫び申し上げます。ソリューションがどこに配置され、どのように使用されるかを学ぶのを助けるためだけに、この構造内にソリューションを適合させる必要があります。

注: これは、マークされた質問の複製ではありません。これがおそらくだましている質問では、テキストを音声に変換できますが、リストされたランダムな応答を音声に変換することはできません。これは私が必要としていたことです。しかし、おかげでスピーチを機能させることができました。他の場所で答えを見つけて、下に置きました。

4

1 に答える 1