hemanth / app.py
iamironman4279's picture
create app.py
da37fd1
raw
history blame
1.62 kB
import whisper
import gradio as gr
import openai
from TTS.api import TTS
# Create an instance of the TTS class
tts = TTS()
# Call the list_models() method on the instance
model_list = tts.list_models()
# Now, you can access the models in the model_list and choose one
model_name = model_list[9]
# Create another instance of the TTS class with the selected model
tts = TTS(model_name)
tts.tts_to_file(text="I love playing Chess", file_path="output.wav")
from IPython.display import Audio, display
display(Audio('output.wav', autoplay=True))
model = whisper.load_model("medium")
openai.api_key = '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'
def voice_chat(user_voice):
messages = [
{"role": "system", "content": "You are a kind helpful assistant."},
]
user_message = model.transcribe(user_voice)["text"]
#reply = user_message
messages.append(
{"role": "user", "content": user_message},
)
print(messages)
chat = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=messages
)
reply = chat.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
tts.tts_to_file(text=reply, file_path="output.wav")
return(reply, 'output.wav')
text_reply = gr.Textbox(label="ChatGPT Text")
voice_reply = gr.Audio('output.wav')
gr.Interface(
title = 'AI Voice Assistant with ChatGPT AI',
fn=voice_chat,
inputs=[
gr.inputs.Audio(source="microphone", type="filepath")
],
outputs=[
text_reply, voice_reply
], live = True).launch(debug = True)