yadongxie commited on
Commit
b911576
1 Parent(s): 30d4448

chore: remove pause detect

Browse files
Files changed (1) hide show
  1. app.py +1 -29
app.py CHANGED
@@ -11,18 +11,14 @@ import base64
11
  import uuid
12
  import os
13
 
14
- print(os.getenv("API_KEY"))
15
-
16
 
17
  @dataclass
18
  class AppState:
19
  stream: np.ndarray | None = None
20
  sampling_rate: int = 0
21
- pause_detected: bool = False
22
  conversation: list = field(default_factory=list)
23
  client: openai.OpenAI = None
24
  output_format: str = "mp3"
25
- stopped: bool = False
26
 
27
 
28
  # Global lock for thread safety
@@ -44,23 +40,6 @@ def test_api_key(client):
44
  raise e
45
 
46
 
47
- def determine_pause(audio, sampling_rate, state):
48
- # Take the last 1 second of audio
49
- pause_length = int(sampling_rate * 1) # 1 second
50
- if len(audio) < pause_length:
51
- return False
52
- last_audio = audio[-pause_length:]
53
- amplitude = np.abs(last_audio)
54
-
55
- # Calculate the average amplitude in the last 1 second
56
- avg_amplitude = np.mean(amplitude)
57
- silence_threshold = 0.01 # Adjust this threshold as needed
58
- if avg_amplitude < silence_threshold:
59
- return True
60
- else:
61
- return False
62
-
63
-
64
  def process_audio(audio: tuple, state: AppState):
65
  if state.stream is None:
66
  state.stream = audio[1]
@@ -68,13 +47,7 @@ def process_audio(audio: tuple, state: AppState):
68
  else:
69
  state.stream = np.concatenate((state.stream, audio[1]))
70
 
71
- pause_detected = determine_pause(state.stream, state.sampling_rate, state)
72
- state.pause_detected = pause_detected
73
-
74
- if state.pause_detected:
75
- return gr.Audio(recording=False), state
76
- else:
77
- return None, state
78
 
79
 
80
  def update_or_append_conversation(conversation, id, role, new_content):
@@ -169,7 +142,6 @@ def response(state: AppState):
169
 
170
  # Reset the audio stream for the next interaction
171
  state.stream = None
172
- state.pause_detected = False
173
 
174
 
175
  def set_api_key(api_key, state):
 
11
  import uuid
12
  import os
13
 
 
 
14
 
15
  @dataclass
16
  class AppState:
17
  stream: np.ndarray | None = None
18
  sampling_rate: int = 0
 
19
  conversation: list = field(default_factory=list)
20
  client: openai.OpenAI = None
21
  output_format: str = "mp3"
 
22
 
23
 
24
  # Global lock for thread safety
 
40
  raise e
41
 
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  def process_audio(audio: tuple, state: AppState):
44
  if state.stream is None:
45
  state.stream = audio[1]
 
47
  else:
48
  state.stream = np.concatenate((state.stream, audio[1]))
49
 
50
+ return None, state
 
 
 
 
 
 
51
 
52
 
53
  def update_or_append_conversation(conversation, id, role, new_content):
 
142
 
143
  # Reset the audio stream for the next interaction
144
  state.stream = None
 
145
 
146
 
147
  def set_api_key(api_key, state):