Skip to content

Commit 634c19e

Browse files
eric-hsiungcobot
authored andcommitted
Add an option to disable processing anything from the audio_pipe. This is for use cases where the speech to text service is not available.
1 parent 6c5bf86 commit 634c19e

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

codebotler.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,18 @@ async def start_ws_server(args, fd):
313313
args.ip, args.ws_port)
314314
print(f"WebSocket server started at ws://{args.ip}:{args.ws_port}")
315315

316-
broadcast_task = asyncio.create_task(
317-
broadcast_transcripts_from_pipe(
318-
args, fd, acc, websocket_server, connected_clients, last_gen_code, lock, executor))
316+
## If the audio_pipe fd is not available for us to use, then we will only process interactions
317+
## using the websocket server.
318+
## If the audio_pipe fd is available for us to use, then we will be able to handle requests from
319+
## both the audio_pipe and the webinterface text boxes.
320+
if fd is not None:
321+
broadcast_task = asyncio.create_task(
322+
broadcast_transcripts_from_pipe(
323+
args, fd, acc, websocket_server, connected_clients, last_gen_code, lock, executor))
324+
await asyncio.gather(websocket_server.wait_closed(), broadcast_task)
325+
else:
326+
await asyncio.gather(websocket_server.wait_closed())
319327

320-
await asyncio.gather(websocket_server.wait_closed(), broadcast_task)
321328
executor.shutdown(wait=False)
322329

323330
def start_completion_callback(args, fd):
@@ -393,7 +400,7 @@ def main():
393400
parser.add_argument('--robot', action='store_true', help='Flag to indicate if the robot is available')
394401
parser.add_argument('--timeout', type=int, help='Code generation timeout in seconds', default=20)
395402
parser.add_argument('--transcription-pipe', type=Path, help='Pipe from which to read audio transcriptions', default='/tmp/audio_pipe')
396-
403+
parser.add_argument('--disable-pipe', action='store_true', default=False, help='Specify this flag to disable the audio pipe')
397404
args = parser.parse_args()
398405

399406
robot_available = args.robot
@@ -413,8 +420,14 @@ def main():
413420
args=[args])
414421
server_thread.start()
415422

416-
## Opens in read-write mode to prevent EOF.
417-
pipe_descriptor = os.open(args.transcription_pipe, os.O_RDWR)
423+
## On certain platforms, we need to be able to disable reading from the pipe because it will not be available.
424+
## In those cases, make sure the pipe_descriptor is None, and make sure we skip trying to open and read from it.
425+
if not args.disable_pipe:
426+
## Opens in read-write mode to prevent EOF.
427+
pipe_descriptor = os.open(args.transcription_pipe, os.O_RDWR)
428+
else:
429+
pipe_descriptor = None
430+
418431
start_completion_callback(args, pipe_descriptor)
419432

420433
if __name__ == "__main__":

0 commit comments

Comments
 (0)