Fixed audio option

This commit is contained in:
Joan
2023-08-06 10:33:20 +02:00
parent 1276f64c40
commit b37bc826d3

View File

@@ -63,37 +63,39 @@ async def main(user, message_text, audio):
async with client: async with client:
audio_name, audio_duration = generate_audio(message_text) audio_name, audio_duration = generate_audio(message_text)
logging.info(f"Calling {user}") logging.info(f"Sending message to: {user}")
call = await voip_service.start_call(user)
await client.send_message(user, message_text) await client.send_message(user, message_text)
try: try:
if audio == 'yes': if audio == 'yes':
logging.info(f"Calling {user}")
call = await voip_service.start_call(user)
call.play(f"/data/audio/{audio_name}.raw") call.play(f"/data/audio/{audio_name}.raw")
call_has_ended = False
@call.on_call_state_changed
def state_changed(call, state):
print(f'State changed: {state}')
@call.on_call_ended
async def call_ended(call):
global call_has_ended
call_has_ended = True
t1 = time.perf_counter()
while True:
t2 = time.perf_counter()
await asyncio.sleep(1)
try:
if call.ctrl.call_duration > audio_duration or call_has_ended or (call.state == CallState.WAITING and int(t2-t1) > min(30, RING_WAIT_TIME)) or call.ctrl.call_duration > MAX_CALL_DURATION:
logging.info("Finishing call because of duration")
await call.discard_call()
break
except Exception as e:
logging.error(f"There was an error during the call: {e}")
break
except Exception as e: except Exception as e:
logging.error(f"Error: {e}") logging.error(f"Error: {e}")
call_has_ended = False
@call.on_call_state_changed
def state_changed(call, state):
print(f'State changed: {state}')
@call.on_call_ended
async def call_ended(call):
global call_has_ended
call_has_ended = True
t1 = time.perf_counter()
while True:
t2 = time.perf_counter()
await asyncio.sleep(1)
try:
if call.ctrl.call_duration > audio_duration or call_has_ended or (call.state == CallState.WAITING and int(t2-t1) > min(30, RING_WAIT_TIME)) or call.ctrl.call_duration > MAX_CALL_DURATION:
logging.info("Finishing call because of duration")
await call.discard_call()
break
except Exception as e:
logging.error(f"There was an error during the call: {e}")
break
while True: while True:
time.sleep(5) time.sleep(5)