speech_recognition+chatgpt实现语音交互助手代码

代码语言:python

所属分类:人工智能

代码描述:speech_recognition+chatgpt实现语音交互助手代码,使用最新的gpt-3.5-turbo

代码标签: speech_recognition chatgpt 语音 交互 助手 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
# -*- coding: utf-8 -*
import speech_recognition as sr
import pyttsx3
import openai
import speech

openai.api_key = "skey"

# 创建 TTS 对象
engine = pyttsx3.init()
# 创建 Recognizer 对象
r = sr.Recognizer()

def getopenairesponse(keyword):
    msg = [{"role": "user", "content": 'Hello World'}]
    msg[0]['content'] = keyword
    completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=msg)
    return completion.choices




# while True:
#     say = speech.input() # 接收语音
#     #reps=getopenairesponse(say)
#     speech.say(say) #说话


while True:
    # 使用麦克风录音
    with sr.Microphone() as sour.........完整代码请登录后点击上方下载按钮下载查看

网友评论0