WhisperLive icon indicating copy to clipboard operation
WhisperLive copied to clipboard

numpy.ndarray issue when .Net client used for Whisper live

Open delsepaulydm opened this issue 6 months ago • 4 comments

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)

delsepaulydm avatar Jul 03 '25 23:07 delsepaulydm

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.

zoq avatar Jul 07 '25 06:07 zoq

Yes, please go ahead and open the PR.

delsepaulydm avatar Jul 08 '25 16:07 delsepaulydm

@zoq Have you got any update on the PR?

delsepaulydm avatar Jul 23 '25 14:07 delsepaulydm

@zoq Have you got any update on the pr?

delsepaulydm avatar Sep 07 '25 10:09 delsepaulydm