PoTaTo721 SpicyqSama007 commited on
Commit
0d147db
1 Parent(s): 5bea296

Update app.py (#5)

Browse files

- Update app.py (4b5d9b5edba474b3f489ab40ea4f03b6d36f73d7)


Co-authored-by: anya <SpicyqSama007@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -117,16 +117,21 @@ async def process_audio_input(
117
  ):
118
  if event.type == FishE2EEventType.USER_CODES:
119
  append_to_chat_ctx(ServeVQPart(codes=event.vq_codes), role="user")
120
-
121
  elif event.type == FishE2EEventType.SPEECH_SEGMENT:
 
 
122
  append_to_chat_ctx(ServeVQPart(codes=event.vq_codes))
123
- yield state.get_history(), wav_chunk_header() + event.frame.data, None, None
124
-
125
  elif event.type == FishE2EEventType.TEXT_SEGMENT:
126
  append_to_chat_ctx(ServeTextPart(text=event.text))
127
- yield state.get_history(), None, None, None
 
 
 
 
128
 
129
- yield state.get_history(), None, None, None
 
130
 
131
 
132
  async def process_text_input(
@@ -186,9 +191,7 @@ def create_demo():
186
 
187
  output_audio = gr.Audio(
188
  label="Assistant's Voice",
189
- streaming=True,
190
- autoplay=True,
191
- interactive=False,
192
  )
193
 
194
  send_button = gr.Button("Send", variant="primary")
 
117
  ):
118
  if event.type == FishE2EEventType.USER_CODES:
119
  append_to_chat_ctx(ServeVQPart(codes=event.vq_codes), role="user")
 
120
  elif event.type == FishE2EEventType.SPEECH_SEGMENT:
121
+ result_audio += event.frame.data
122
+ np_audio = np.frombuffer(result_audio, dtype=np.int16)
123
  append_to_chat_ctx(ServeVQPart(codes=event.vq_codes))
124
+ yield state.get_history(), (44100, np_audio), None, None
 
125
  elif event.type == FishE2EEventType.TEXT_SEGMENT:
126
  append_to_chat_ctx(ServeTextPart(text=event.text))
127
+ if result_audio:
128
+ np_audio = np.frombuffer(result_audio, dtype=np.int16)
129
+ yield state.get_history(), (44100, np_audio), None, None
130
+ else:
131
+ yield state.get_history(), None, None, None
132
 
133
+ np_audio = np.frombuffer(result_audio, dtype=np.int16)
134
+ yield state.get_history(), (44100, np_audio), None, None
135
 
136
 
137
  async def process_text_input(
 
191
 
192
  output_audio = gr.Audio(
193
  label="Assistant's Voice",
194
+ type="numpy",
 
 
195
  )
196
 
197
  send_button = gr.Button("Send", variant="primary")