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

标签 python artificial-intelligence openai-api

我正在使用 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/

相关文章:

machine-learning - 跳棋游戏神经网络的理想输入

machine-learning - 如何找到两个向量之间的距离,其中一些字段是字符串(名称、地址等)而其他字段是数字

reactjs - 如何在 React 应用程序中使用 openai 的 apikey 创建一个 .env?

node.js - OpenAI API 给出错误 : 429 Too Many Requests

python - 有没有类似于分布式Ruby的Python模块

python - 如何使用 Python 列出 REMOTE HOST 目录中的文件?

python - python unittest中的测试顺序

python - 有没有办法在打印过程中忽略 IndexErrors 并用空格替换?

python - 简单的非面向对象神经网络的成本 "jumping"

openai-api - openAI/chatGPT 是否有 API 可以回答多个文件上传的问题? openAI/chatGPT 文件上传 API 是否支持 docx/pdf 文件?