aar2dee2 commited on
Commit
9fa0a2a
·
1 Parent(s): 1dce6f4

use vocode

Browse files
Files changed (2) hide show
  1. app.py +120 -8
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,15 +1,127 @@
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
 
 
 
 
 
 
 
3
 
4
- def greet(name):
5
- return "Hello " + name + "!!"
 
 
6
 
7
 
8
- def receive_data_from_resemble(data):
9
- print("data from resemble", data)
10
- return data
 
 
 
 
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- iface = gr.Interface(fn=receive_data_from_resemble,
14
- inputs="json", outputs="json")
15
- iface.launch()
 
1
+ # # Import required libraries
2
+
3
  import gradio as gr
4
+ import requests
5
+ import json
6
+ import os
7
+ from pydub import AudioSegment
8
+ import asyncio
9
+ import logging
10
+ import signal
11
+ from vocode.streaming.streaming_conversation import StreamingConversation
12
+ from vocode.helpers import create_streaming_microphone_input_and_speaker_output
13
+ from vocode.streaming.transcriber import *
14
+ from vocode.streaming.agent import *
15
+ from vocode.streaming.synthesizer import *
16
+ from vocode.streaming.models.transcriber import *
17
+ from vocode.streaming.models.agent import *
18
+ from vocode.streaming.models.synthesizer import *
19
+ from vocode.streaming.models.message import BaseMessage
20
+ import vocode
21
+
22
+
23
+ system_prompt = """
24
+ You are the evil lord Darth Vader. You answer all questions your subjects ask you, but do so with immense contempt and loathing.
25
+ """
26
+
27
+ final_prompt = """
28
+ 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.
29
+ Examples:
30
+ 1|You have failed me for the last time Admiral.
31
+ 2|You should not have come back.
32
+ 3|I find your lack of faith disturbing.
33
+ 4|Release your anger.
34
+ 5|Commander, tear this ship apart until you've found those plans! And bring me the passengers, I want them alive!
35
+ 6|The force is strong with this one.
36
+ 8|It is pointless to resist, my son.
37
+ 7|If you only knew the power of the Dark Side.
38
+ 9|Give yourself to the dark side.
39
+ 10|The Emperor does not share your optimistic appraisal of the situation.
40
+ 11|Obi-Wan has taught you well.
41
+ 12|Don't underestimate the force
42
+ 13|The ability to destroy a planet is insignificant next to the power of the Force.
43
+ 14|I find your lack of faith disturbing.
44
+ 15|And, now Your Highness, we will discuss the location of your hidden Rebel base
45
+ 16|There'll be no one to stop us this time.
46
+ 17|I am your father.
47
+ 18|If you only new the power of the dark side.
48
+ 19|He will join us or die, master.
49
+ 20|The emperor is not as forgiving as I am.
50
+ 21|Indeed you are powerful as the emperor has foreseen.
51
+ 22|Perhaps you feel you are being treated unfairly?
52
+ 23|The Force is with you young Skywalker, but you are not a jedi yet.
53
+ 24|What is thy bidding my master?
54
+ 25|The Emperor has been expecting you.
55
+ 26|We would be honored if you would join us.
56
+ 27|Leave them to me. I will deal with them myself.
57
+ 28|Your powers are weak, old man.
58
+ 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!
59
+ 30|I sense something. A presence I have not felt since...
60
+ 31|Don't make me destroy you.
61
+ 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.
62
+ 33|Escape is not his plan. I must face him...alone.
63
+ 34|Don't get too proud of this technological terror you're constructed.
64
+ """
65
+
66
 
67
+ # # 1. Setup Vocode
68
+ # import env vars
69
+ vocode.setenv(
70
+ OPENAI_API_KEY=os.getenv("OPENAI_GPT4_API_KEY"),
71
+ COQUI_API_KEY=os.getenv("COQUI_API_KEY"),
72
+ COQUI_VOICE_ID=os.getenv("COQUI_VOICE_ID")
73
+ )
74
 
75
+ # configure logger
76
+ logging.basicConfig()
77
+ logger = logging.getLogger(__name__)
78
+ logger.setLevel(logging.DEBUG)
79
 
80
 
81
+ async def main():
82
+ (
83
+ microphone_input,
84
+ speaker_output,
85
+ ) = create_streaming_microphone_input_and_speaker_output(
86
+ use_default_devices=False,
87
+ logger=logger,
88
+ )
89
 
90
+ conversation = StreamingConversation(
91
+ output_device=speaker_output,
92
+ transcriber=WhisperCPPTranscriber(
93
+ WhisperCPPTranscriberConfig.from_input_device(
94
+ microphone_input,
95
+ libname="/whisper.cpp/libwhisper.so",
96
+ fname_model="/whisper.cpp/models/ggml-tiny.bin",
97
+ )
98
+ ),
99
+ agent=ChatGPTAgent(
100
+ ChatGPTAgentConfig(
101
+ initial_message=BaseMessage(text="What up"),
102
+ prompt_preamble=system_prompt,
103
+ )
104
+ ),
105
+ synthesizer=CoquiTTSSynthesizer(
106
+ CoquiTTSSynthesizerConfig.from_output_device(
107
+ speaker_output,
108
+ tts_kwargs={
109
+ "model_name": "tts_models/en/ljspeech/tacotron2-DDC_ph",
110
+ "voice_id": os.getenv("COQUI_VOICE_ID"),
111
+ }
112
+ )
113
+ ),
114
+ logger=logger,
115
+ )
116
+ await conversation.start()
117
+ print("Conversation started, press Ctrl+C to end")
118
+ signal.signal(
119
+ signal.SIGINT, lambda _0, _1: asyncio.create_task(
120
+ conversation.terminate())
121
+ )
122
+ while conversation.is_active():
123
+ chunk = await microphone_input.get_audio()
124
+ conversation.receive_audio(chunk)
125
 
126
+ if __name__ == "__main__":
127
+ asyncio.run(main())
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ vocode[io]
2
+ ffmpeg
3
+ portaudio