Skip to content

Commit

Permalink
specify dtype for librosa.load, instead of cast
Browse files Browse the repository at this point in the history
  • Loading branch information
koiking213 committed Feb 20, 2024
1 parent 6211946 commit d22a5ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions whisper_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

@lru_cache
def load_audio(fname):
a, _ = librosa.load(fname, sr=16000)
return a.astype('float32')
a, _ = librosa.load(fname, sr=16000, dtype=np.float32)
return a

def load_audio_chunk(fname, beg, end):
audio = load_audio(fname)
Expand Down
5 changes: 3 additions & 2 deletions whisper_online_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import argparse
import os
import numpy as np
parser = argparse.ArgumentParser()

# server options
Expand Down Expand Up @@ -137,8 +138,8 @@ def receive_audio_chunk(self):
if not raw_bytes:
break
sf = soundfile.SoundFile(io.BytesIO(raw_bytes), channels=1,endian="LITTLE",samplerate=SAMPLING_RATE, subtype="PCM_16",format="RAW")
audio, _ = librosa.load(sf,sr=SAMPLING_RATE)
out.append(audio.astype('float32'))
audio, _ = librosa.load(sf,sr=SAMPLING_RATE,dtype=np.float32)
out.append(audio)
if not out:
return None
return np.concatenate(out)
Expand Down

0 comments on commit d22a5ef

Please sign in to comment.