Skip to content

Commit

Permalink
Avoid division by zero (livekit#153)
Browse files Browse the repository at this point in the history
* Avoid division by zero

I saw the following in one of my tests:
```
Traceback (most recent call last):
  File "/Users/shahafabileah/work/vocode/vocode-python/vocode/streaming/utils/worker.py", line 167, in _run_loop
    await self.current_task
  File "/Users/shahafabileah/work/vocode/vocode-python/vocode/streaming/streaming_conversation.py", line 284, in process
    message_sent, cut_off = await self.conversation.send_speech_to_output(
  File "/Users/shahafabileah/work/vocode/vocode-python/vocode/streaming/streaming_conversation.py", line 515, in send_speech_to_output
    message_sent = f"{synthesis_result.get_message_up_to(seconds)}-"
  File "/Users/shahafabileah/work/vocode/vocode-python/vocode/streaming/synthesizer/base_synthesizer.py", line 212, in <lambda>
    lambda seconds: self.get_message_cutoff_from_total_response_length(
  File "/Users/shahafabileah/work/vocode/vocode-python/vocode/streaming/synthesizer/base_synthesizer.py", line 161, in get_message_cutoff_from_total_response_length
    estimated_output_seconds_per_char = estimated_output_seconds / len(message.text)
ZeroDivisionError: float division by zero
```

I haven't dug deeper to understand why the message is empty, and I don't know if 1 is a good fallback value.

* return string

---------

Co-authored-by: Kian <[email protected]>
  • Loading branch information
shahafabileah and Kian1354 authored May 26, 2023
1 parent b60240a commit cda2fd3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vocode/streaming/synthesizer/base_synthesizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def get_message_cutoff_from_total_response_length(
estimated_output_seconds = (
size_of_output / self.synthesizer_config.sampling_rate
)
if not message.text:
return message.text

estimated_output_seconds_per_char = estimated_output_seconds / len(message.text)
return message.text[: int(seconds / estimated_output_seconds_per_char)]

Expand Down

0 comments on commit cda2fd3

Please sign in to comment.