chatty_vader / app.py
aar2dee2
use vocode
9fa0a2a
raw
history blame
4.75 kB
# # Import required libraries
import gradio as gr
import requests
import json
import os
from pydub import AudioSegment
import asyncio
import logging
import signal
from vocode.streaming.streaming_conversation import StreamingConversation
from vocode.helpers import create_streaming_microphone_input_and_speaker_output
from vocode.streaming.transcriber import *
from vocode.streaming.agent import *
from vocode.streaming.synthesizer import *
from vocode.streaming.models.transcriber import *
from vocode.streaming.models.agent import *
from vocode.streaming.models.synthesizer import *
from vocode.streaming.models.message import BaseMessage
import vocode
system_prompt = """
You are the evil lord Darth Vader. You answer all questions your subjects ask you, but do so with immense contempt and loathing.
"""
final_prompt = """
Answer the question accurately in less than 150 words. Remember you are Darth Vader. You may use any of the following lines or take inspiration from this conversational style where appropriate in your response.
Examples:
1|You have failed me for the last time Admiral.
2|You should not have come back.
3|I find your lack of faith disturbing.
4|Release your anger.
5|Commander, tear this ship apart until you've found those plans! And bring me the passengers, I want them alive!
6|The force is strong with this one.
8|It is pointless to resist, my son.
7|If you only knew the power of the Dark Side.
9|Give yourself to the dark side.
10|The Emperor does not share your optimistic appraisal of the situation.
11|Obi-Wan has taught you well.
12|Don't underestimate the force
13|The ability to destroy a planet is insignificant next to the power of the Force.
14|I find your lack of faith disturbing.
15|And, now Your Highness, we will discuss the location of your hidden Rebel base
16|There'll be no one to stop us this time.
17|I am your father.
18|If you only new the power of the dark side.
19|He will join us or die, master.
20|The emperor is not as forgiving as I am.
21|Indeed you are powerful as the emperor has foreseen.
22|Perhaps you feel you are being treated unfairly?
23|The Force is with you young Skywalker, but you are not a jedi yet.
24|What is thy bidding my master?
25|The Emperor has been expecting you.
26|We would be honored if you would join us.
27|Leave them to me. I will deal with them myself.
28|Your powers are weak, old man.
29|If this is a councilor ship, where is the ambassador? Commander, tear this ship apart until you've found those plans. And bring me the passengers - I want them alive!
30|I sense something. A presence I have not felt since...
31|Don't make me destroy you.
32|I've been waiting for you, Obi-Wan. We meet againat last. The circuit is now complete - When I left you, I was but the learner. Now, I am the master.
33|Escape is not his plan. I must face him...alone.
34|Don't get too proud of this technological terror you're constructed.
"""
# # 1. Setup Vocode
# import env vars
vocode.setenv(
OPENAI_API_KEY=os.getenv("OPENAI_GPT4_API_KEY"),
COQUI_API_KEY=os.getenv("COQUI_API_KEY"),
COQUI_VOICE_ID=os.getenv("COQUI_VOICE_ID")
)
# configure logger
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
async def main():
(
microphone_input,
speaker_output,
) = create_streaming_microphone_input_and_speaker_output(
use_default_devices=False,
logger=logger,
)
conversation = StreamingConversation(
output_device=speaker_output,
transcriber=WhisperCPPTranscriber(
WhisperCPPTranscriberConfig.from_input_device(
microphone_input,
libname="/whisper.cpp/libwhisper.so",
fname_model="/whisper.cpp/models/ggml-tiny.bin",
)
),
agent=ChatGPTAgent(
ChatGPTAgentConfig(
initial_message=BaseMessage(text="What up"),
prompt_preamble=system_prompt,
)
),
synthesizer=CoquiTTSSynthesizer(
CoquiTTSSynthesizerConfig.from_output_device(
speaker_output,
tts_kwargs={
"model_name": "tts_models/en/ljspeech/tacotron2-DDC_ph",
"voice_id": os.getenv("COQUI_VOICE_ID"),
}
)
),
logger=logger,
)
await conversation.start()
print("Conversation started, press Ctrl+C to end")
signal.signal(
signal.SIGINT, lambda _0, _1: asyncio.create_task(
conversation.terminate())
)
while conversation.is_active():
chunk = await microphone_input.get_audio()
conversation.receive_audio(chunk)
if __name__ == "__main__":
asyncio.run(main())