Dominik Machacek commited on
Commit
726fa57
·
1 Parent(s): 706b7f8

fix bug in server

Browse files
Files changed (1) hide show
  1. whisper_online_server.py +7 -6
whisper_online_server.py CHANGED
@@ -89,7 +89,7 @@ import logging
89
 
90
  class Connection:
91
  '''it wraps conn object'''
92
- PACKET_SIZE = 65536
93
 
94
  def __init__(self, conn):
95
  self.conn = conn
@@ -109,8 +109,11 @@ class Connection:
109
  return in_line
110
 
111
  def non_blocking_receive_audio(self):
112
- r = self.conn.recv(self.PACKET_SIZE)
113
- return r
 
 
 
114
 
115
 
116
  import io
@@ -134,8 +137,7 @@ class ServerProcessor:
134
  out = []
135
  while sum(len(x) for x in out) < self.min_chunk*SAMPLING_RATE:
136
  raw_bytes = self.connection.non_blocking_receive_audio()
137
- print(raw_bytes[:10])
138
- print(len(raw_bytes))
139
  if not raw_bytes:
140
  break
141
  sf = soundfile.SoundFile(io.BytesIO(raw_bytes), channels=1,endian="LITTLE",samplerate=SAMPLING_RATE, subtype="PCM_16",format="RAW")
@@ -203,7 +205,6 @@ logging.basicConfig(level=level, format='whisper-server-%(levelname)s: %(message
203
  # server loop
204
 
205
  with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
206
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
207
  s.bind((args.host, args.port))
208
  s.listen(1)
209
  logging.info('INFO: Listening on'+str((args.host, args.port)))
 
89
 
90
  class Connection:
91
  '''it wraps conn object'''
92
+ PACKET_SIZE = 32000*5*60 # 5 minutes # was: 65536
93
 
94
  def __init__(self, conn):
95
  self.conn = conn
 
109
  return in_line
110
 
111
  def non_blocking_receive_audio(self):
112
+ try:
113
+ r = self.conn.recv(self.PACKET_SIZE)
114
+ return r
115
+ except ConnectionResetError:
116
+ return None
117
 
118
 
119
  import io
 
137
  out = []
138
  while sum(len(x) for x in out) < self.min_chunk*SAMPLING_RATE:
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")
 
205
  # server loop
206
 
207
  with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
 
208
  s.bind((args.host, args.port))
209
  s.listen(1)
210
  logging.info('INFO: Listening on'+str((args.host, args.port)))