gpt4 book ai didi

python - 我需要一些帮助来修复一个 python 脚本,该脚本为 chatgpt 提供人形语音,并允许我使用自己的声音与它交谈

转载 作者:行者123 更新时间:2023-12-02 22:48:29 32 4
gpt4 key购买 nike

我发现下面的Python脚本应该能够提供逼真的人形语音来聊天gpt,将其产生的文本转换为人形语音,并使用我的声音和麦克风与它交谈。简而言之,我想做与“amazon echo/Alexa”语音助手相同的事情,但不购买它,但只使用我已经拥有的……Jetson nano。为什么选择 Jetson nano?因为我可以把它从家里的一个地方移动到另一个地方,就像语音助手一样,而且因为我已经花了一些钱买了它并且我想使用它。这是我找到的视频教程:

https://www.youtube.com/watch?v=8z8Cobsvc9k

这是代码:

import openai
import speech_recognition as sr
import pyttsx3
import time

# Initialize OpenAI API

openai.api_key = "ciao a tutti"

# Initialize the text to speech engine

engine=pyttsx3.init()

def transcribe_audio_to_test(filename):

recogizer=sr.Recognizer()

with sr.AudioFile(filename)as source:

audio=recogizer.record(source)

try:

return recogizer.recognize_google(audio)

except:

print("skipping unkown error")


def generate_response(prompt):

response= openai.completion.create(

engine="text-davinci-003",

prompt=prompt,

max_tokens=4000,

n=1,

stop=None,

temperature=0.5,

)

return response ["Choices"][0]["text"]

def speak_text(text):

engine.say(text)

engine.runAndWait()



def main():

while True:

#Waith for user say "genius"

print("Say 'Genius' to start recording your question")

with sr.Microphone() as source:

recognizer=sr.Recognizer()

audio=recognizer.listen(source)

try:

transcription = recognizer.recognize_google(audio)

if transcription.lower()=="genius":

#record audio

filename ="input.wav"

print("Say your question")

with sr.Microphone() as source:

recognizer=sr.recognize()

source.pause_threshold=1

audio=recognizer.listen(source,phrase_time_limit=None,timeout=None)

with open(filename,"wb")as f:

f.write(audio.get_wav_data())



#transcript audio to test

text=transcribe_audio_to_test(filename)

if text:

print(f"yuo said {text}")



#Generate the response

response = generate_response(text)

print(f"chat gpt 3 say {response}")



#read resopnse using GPT3

speak_text(response)

except Exception as e:



print("An error ocurred : {}".format(e))

if __name__=="__main__":

main()

我尝试使用 pip 安装 openai :

marietto@marietto:/mnt/fisso/OS/Alexa-ChatGPT# python3 code.py

Traceback (most recent call last):
File "code.py", line 1, in <module>
import openai
ModuleNotFoundError: No module named 'openai'

marietto@marietto:/mnt/fisso/OS/Alexa-ChatGPT# pip install openai

Collecting openai
Downloading openai-0.27.2-py3-none-any.whl (70 kB)
|????????????????????????????????| 70 kB 1.3 MB/s
Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.8/dist-packages (from openai) (2.28.2)
Requirement already satisfied: tqdm in /usr/local/lib/python3.8/dist-packages (from openai) (4.62.3)
Collecting aiohttp
Downloading aiohttp-3.8.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB)
|????????????????????????????????| 1.0 MB 6.7 MB/s
Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3/dist-packages (from requests>=2.20->openai) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests>=2.20->openai) (2019.11.28)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3/dist-packages (from requests>=2.20->openai) (1.25.8)
Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.8/dist-packages (from requests>=2.20->openai) (2.0.6)
Requirement already satisfied: attrs>=17.3.0 in /usr/lib/python3/dist-packages (from aiohttp->openai) (19.3.0)
Collecting yarl<2.0,>=1.0
Downloading yarl-1.8.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (258 kB)
|????????????????????????????????| 258 kB 10.4 MB/s
Collecting aiosignal>=1.1.2
Downloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)
Collecting multidict<7.0,>=4.5
Downloading multidict-6.0.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (124 kB)
|????????????????????????????????| 124 kB 9.7 MB/s
Collecting async-timeout<5.0,>=4.0.0a3
Downloading async_timeout-4.0.2-py3-none-any.whl (5.8 kB)
Collecting frozenlist>=1.1.1
Downloading frozenlist-1.3.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (162 kB)
|????????????????????????????????| 162 kB 9.4 MB/s
Installing collected packages: multidict, yarl, frozenlist, aiosignal, async-timeout, aiohttp, openai
Successfully installed aiohttp-3.8.4 aiosignal-1.3.1 async-timeout-4.0.2 frozenlist-1.3.3 multidict-6.0.4 openai-0.27.2 yarl-1.8.2

使用 pip3 :

marietto@marietto:/mnt/fisso/OS/Alexa-ChatGPT# pip3 install openai

Requirement already satisfied: openai in /usr/local/lib/python3.8/dist-packages (0.27.2)
Requirement already satisfied: tqdm in /usr/local/lib/python3.8/dist-packages (from openai) (4.62.3)
Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.8/dist-packages (from openai) (2.28.2)
Requirement already satisfied: aiohttp in /usr/local/lib/python3.8/dist-packages (from openai) (3.8.4)
Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3/dist-packages (from requests>=2.20->openai) (2.8)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3/dist-packages (from requests>=2.20->openai) (1.25.8)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests>=2.20->openai) (2019.11.28)
Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.8/dist-packages (from requests>=2.20->openai) (2.0.6)
Requirement already satisfied: attrs>=17.3.0 in /usr/lib/python3/dist-packages (from aiohttp->openai) (19.3.0)
Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.8/dist-packages (from aiohttp->openai) (1.3.3)
Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.8/dist-packages (from aiohttp->openai) (1.3.1)
Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.8/dist-packages (from aiohttp->openai) (6.0.4)
Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /usr/local/lib/python3.8/dist-packages (from aiohttp->openai) (4.0.2)
Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.8/dist-packages (from aiohttp->openai) (1.8.2)

但是它不起作用:

marietto@marietto:/mnt/fisso/OS/Alexa-ChatGPT# python3 code.py

Illegal instruction (core dumped)

有人可以帮我解决问题所在吗?

在 jetson nano 上我运行的是 ubuntu 20.04 和这些版本的 python :

marietto@marietto:/mnt/fisso/OS/Alexa-ChatGPT# python3 --version
Python 3.8.10

marietto@marietto:/mnt/fisso/OS/Alexa-ChatGPT# python --version
Python 2.7.18

最佳答案

您是否尝试过升级您的Python版本?考虑到 ChatGPT 是新的,您可能需要 3.10 或更高版本。

如果您使用 conda,您可以运行以下命令:conda更新python

如果您使用Linux,您可以使用: sudo apt update,然后输入密码,然后输入sudo apt install python3.10

如果您使用 Mac,请使用 this link 。或者,如果您有 Homebrew,则可以使用 brew install python

最后,如果您使用Windows,您可以访问Python downloads page并安装最新版本。

关于python - 我需要一些帮助来修复一个 python 脚本,该脚本为 chatgpt 提供人形语音,并允许我使用自己的声音与它交谈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75848481/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com