gpt4 book ai didi

python - 我怎样才能实现文本到语音呢?

转载 作者:行者123 更新时间:2023-12-02 05:48:03 25 4
gpt4 key购买 nike

我正在使用 OpenAI 与 AI 交谈,但为了与它交谈,我必须在提示部分输入人类,打印响应,然后它会跟我说话,但只有一次。有没有办法实现文本到语音和语音到文本?

import os
import openai

openai.api_key = 'not saying my api key'

start_sequence = "\nAI:"
restart_sequence = "\nHuman: "

response = openai.Completion.create(
model="text-davinci-002",
prompt="The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\n\nHuman: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?\nHuman: ",
temperature=0.9,
max_tokens=150,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=[" Human:", " AI:"]
)

print(response)

最佳答案

如果您使用的是笔记本:

import os
from gtts import gTTS
from IPython.display import Audio, display

def talk(text):
# convert text to speech, save to audio file
gTTS(text).save('temp.wav')
# load audio file, play sound
display(Audio('temp.wav', autoplay=True))
# remove temporary file
os.remove('temp.wav')

关于python - 我怎样才能实现文本到语音呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73533043/

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