bugfix
This commit is contained in:
parent
726fa574a2
commit
884958127f
1 changed files with 9 additions and 2 deletions
|
|
@ -130,21 +130,28 @@ class ServerProcessor:
|
||||||
|
|
||||||
self.last_end = None
|
self.last_end = None
|
||||||
|
|
||||||
|
self.is_first = True
|
||||||
|
|
||||||
def receive_audio_chunk(self):
|
def receive_audio_chunk(self):
|
||||||
# receive all audio that is available by this time
|
# receive all audio that is available by this time
|
||||||
# blocks operation if less than self.min_chunk seconds is available
|
# blocks operation if less than self.min_chunk seconds is available
|
||||||
# unblocks if connection is closed or a chunk is available
|
# unblocks if connection is closed or a chunk is available
|
||||||
out = []
|
out = []
|
||||||
while sum(len(x) for x in out) < self.min_chunk*SAMPLING_RATE:
|
minlimit = self.min_chunk*SAMPLING_RATE
|
||||||
|
while sum(len(x) for x in out) < minlimit:
|
||||||
raw_bytes = self.connection.non_blocking_receive_audio()
|
raw_bytes = self.connection.non_blocking_receive_audio()
|
||||||
print("received audio:",len(raw_bytes), "bytes", raw_bytes[:10])
|
|
||||||
if not raw_bytes:
|
if not raw_bytes:
|
||||||
break
|
break
|
||||||
|
print("received audio:",len(raw_bytes), "bytes", raw_bytes[:10])
|
||||||
sf = soundfile.SoundFile(io.BytesIO(raw_bytes), channels=1,endian="LITTLE",samplerate=SAMPLING_RATE, subtype="PCM_16",format="RAW")
|
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)
|
audio, _ = librosa.load(sf,sr=SAMPLING_RATE)
|
||||||
out.append(audio)
|
out.append(audio)
|
||||||
if not out:
|
if not out:
|
||||||
return None
|
return None
|
||||||
|
conc = np.concatenate(out)
|
||||||
|
if self.is_first and len(conc) < minlimit:
|
||||||
|
return None
|
||||||
|
self.is_first = False
|
||||||
return np.concatenate(out)
|
return np.concatenate(out)
|
||||||
|
|
||||||
def format_output_transcript(self,o):
|
def format_output_transcript(self,o):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue