MCPcopy Index your code
hub / github.com/Standard-Intelligence/hertz-dev / process_audio

Method process_audio

inference_client_webrtc.py:89–116  ·  view source on GitHub ↗
(self, audio_data: np.ndarray)

Source from the content-addressed store, hash-verified

87 return audio_data
88
89 async def process_audio(self, audio_data: np.ndarray) -> np.ndarray:
90 if self.ws is None:
91 self.ws = await websockets.connect(self.server_url)
92
93 audio_data = audio_data.reshape(-1, CHANNELS)
94 print(f'Data from microphone:{audio_data.shape, audio_data.dtype, audio_data.min(), audio_data.max()}')
95
96 # Convert to base64
97 audio_b64 = base64.b64encode(audio_data.tobytes()).decode('utf-8')
98
99 # Send to server
100 time_sent = time.time()
101 await self.ws.send(f"data:audio/raw;base64,{audio_b64}")
102
103 # Receive processed audio
104 response = await self.ws.recv()
105 response = response.split(",")[1]
106 time_received = time.time()
107 print(f"Data sent: {audio_b64[:10]}. Data received: {response[:10]}. Received in {(time_received - time_sent) * 1000:.2f} ms")
108 processed_audio = np.frombuffer(
109 base64.b64decode(response),
110 dtype=np.int16
111 ).reshape(-1, CHANNELS)
112 print(f'Data from model:{processed_audio.shape, processed_audio.dtype, processed_audio.min(), processed_audio.max()}')
113
114 if CHANNELS == 1:
115 processed_audio = processed_audio.reshape(-1)
116 return processed_audio
117
118 async def queued_audio_frames_callback(self, frames: List[av.AudioFrame]) -> List[av.AudioFrame]:
119 out_frames = []

Callers 1

Calls 1

decodeMethod · 0.80

Tested by

no test coverage detected