代码如下:

import openai
import pyttsx3

openai.api_key = "sk-........................"  # 你的 OpenAI API Key
while True:
    askmsg = input()
    # create a completion
    completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", \
                                        messages=[{"role": "user", "content": askmsg}])

    # get the text from the completion
    text = completion.choices[0].message.content

    # create a TTS engine and play the text as speech
    engine = pyttsx3.init()
    engine.say(text)
    engine.runAndWait()

发表评论