Dominik Machacek
commited on
Commit
·
8849581
1
Parent(s):
726fa57
bugfix
Browse files- whisper_online_server.py +9 -2
whisper_online_server.py
CHANGED
@@ -130,21 +130,28 @@ class ServerProcessor:
|
|
130 |
|
131 |
self.last_end = None
|
132 |
|
|
|
|
|
133 |
def receive_audio_chunk(self):
|
134 |
# receive all audio that is available by this time
|
135 |
# blocks operation if less than self.min_chunk seconds is available
|
136 |
# unblocks if connection is closed or a chunk is available
|
137 |
out = []
|
138 |
-
|
|
|
139 |
raw_bytes = self.connection.non_blocking_receive_audio()
|
140 |
-
print("received audio:",len(raw_bytes), "bytes", raw_bytes[:10])
|
141 |
if not raw_bytes:
|
142 |
break
|
|
|
143 |
sf = soundfile.SoundFile(io.BytesIO(raw_bytes), channels=1,endian="LITTLE",samplerate=SAMPLING_RATE, subtype="PCM_16",format="RAW")
|
144 |
audio, _ = librosa.load(sf,sr=SAMPLING_RATE)
|
145 |
out.append(audio)
|
146 |
if not out:
|
147 |
return None
|
|
|
|
|
|
|
|
|
148 |
return np.concatenate(out)
|
149 |
|
150 |
def format_output_transcript(self,o):
|
|
|
130 |
|
131 |
self.last_end = None
|
132 |
|
133 |
+
self.is_first = True
|
134 |
+
|
135 |
def receive_audio_chunk(self):
|
136 |
# receive all audio that is available by this time
|
137 |
# blocks operation if less than self.min_chunk seconds is available
|
138 |
# unblocks if connection is closed or a chunk is available
|
139 |
out = []
|
140 |
+
minlimit = self.min_chunk*SAMPLING_RATE
|
141 |
+
while sum(len(x) for x in out) < minlimit:
|
142 |
raw_bytes = self.connection.non_blocking_receive_audio()
|
|
|
143 |
if not raw_bytes:
|
144 |
break
|
145 |
+
print("received audio:",len(raw_bytes), "bytes", raw_bytes[:10])
|
146 |
sf = soundfile.SoundFile(io.BytesIO(raw_bytes), channels=1,endian="LITTLE",samplerate=SAMPLING_RATE, subtype="PCM_16",format="RAW")
|
147 |
audio, _ = librosa.load(sf,sr=SAMPLING_RATE)
|
148 |
out.append(audio)
|
149 |
if not out:
|
150 |
return None
|
151 |
+
conc = np.concatenate(out)
|
152 |
+
if self.is_first and len(conc) < minlimit:
|
153 |
+
return None
|
154 |
+
self.is_first = False
|
155 |
return np.concatenate(out)
|
156 |
|
157 |
def format_output_transcript(self,o):
|