numpy.ndarray issue when .Net client used for Whisper live
When connecting from vb.net to whisper live server for real time transcriptions, bytes of audio sent throws numpy.ndarray error. The issue is resolved in the python client by converting it using _def bytes_to_float_array(audio_bytes): If this function is transferred to server.py on the audio received, the same whisper live server can be used for .Net Clients also.
Add below function to server.py
def ensure_numpy_array(self,audio_data):
if isinstance(audio_data, np.ndarray):
return audio_data
elif isinstance(audio_data, bytes):
# Convert raw PCM 16-bit mono to int16 numpy array
audio_np = np.frombuffer(audio_data, dtype=np.int16)
# Normalize to float32 range [-1.0, 1.0]
return audio_np.astype(np.float32) / 32768.0
else:
raise TypeError(f"Unsupported audio data type: {type(audio_data)}")
Update def get_audio_from_websocket(self, websocket) to
def get_audio_from_websocket(self, websocket):
frame_data = websocket.recv()
if frame_data == b"END_OF_AUDIO":
return False
audioBytes=self.ensure_numpy_array(frame_data)
return np.frombuffer(audioBytes, dtype=np.float32)
#return np.frombuffer(frame_data, dtype=np.float32)
Thanks for opening the issue, the proposed patch looks good to me, let me know if you like me top open a PR with the patch.
Yes, please go ahead and open the PR.
@zoq Have you got any update on the PR?
@zoq Have you got any update on the pr?