Udyan commited on
Commit
528c943
·
verified ·
1 Parent(s): 20f9cf6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -25,10 +25,15 @@ speaker_embeddings = torch.randn(1, 512)
25
 
26
  def voice_assistant(audio):
27
 
28
- # Speech Text
29
- speech_text = stt(audio)["text"]
30
 
31
- # Generate AI response
 
 
 
 
 
32
  response = llm(
33
  speech_text,
34
  max_new_tokens=60
@@ -42,8 +47,7 @@ def voice_assistant(audio):
42
  speaker_embeddings
43
  )
44
 
45
- # Convert tensor → numpy audio
46
- audio_output = speech.cpu().numpy().astype("float32")
47
 
48
  return speech_text, response, (16000, audio_output)
49
 
 
25
 
26
  def voice_assistant(audio):
27
 
28
+ if audio is None:
29
+ return "No audio detected", "Please record something first.", None
30
 
31
+ sample_rate, audio_data = audio
32
+
33
+ # Speech to text
34
+ speech_text = stt(audio_data)["text"]
35
+
36
+ # AI response
37
  response = llm(
38
  speech_text,
39
  max_new_tokens=60
 
47
  speaker_embeddings
48
  )
49
 
50
+ audio_output = speech.cpu().numpy()
 
51
 
52
  return speech_text, response, (16000, audio_output)
53