Skip to content

Commit

Permalink
clean-up progress printer
Browse files Browse the repository at this point in the history
  • Loading branch information
bejager committed Apr 17, 2024
1 parent 8b56b02 commit 4ed95fe
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 270 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/python-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ jobs:
- name: Install dependencies
run: pip install -r requirements.txt

- name: Test streaming
run: >
python3 orca_demo_streaming.py
--access_key ${{secrets.PV_VALID_ACCESS_KEY}}
--text "Hello, I am Orca!"
--output_path ./tmp.wav
--no-audio
- name: Test single
run: >
python orca_demo.py
Expand Down Expand Up @@ -79,6 +87,7 @@ jobs:
--access_key ${{secrets.PV_VALID_ACCESS_KEY}}
--text "Hello, I am Orca!"
--output_path ./tmp.wav
--no-audio
- name: Test single
run: >
Expand Down
54 changes: 25 additions & 29 deletions demo/llm/orca_voice_assistant_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,9 @@ def main(args: argparse.Namespace) -> None:
llm = LLM.create(llm_type, **llm_init_kwargs)

progress_printer = ProgressPrinter(
show_llm_response=False,
llm_response_init_message="LLM response: ",
show_live_progress_bar=False,
timer_llm_init_message="Wait time for LLM: ",
timer_tts_init_message="Wait time for TTS: ",
timer_llm_message="Time to wait for LLM: ",
timer_tts_message="Time to wait for TTS: ",
progress_bar_symbol=">",
# show_live_progress_bar=True,
# timer_llm_init_message="Wait for LLM: ",
# timer_tts_init_message="Wait for TTS: ",
)

print_welcome_message()
Expand All @@ -127,35 +121,31 @@ def main(args: argparse.Namespace) -> None:

text = user_input.get_user_prompt()

progress_printer.start(f"{synthesizer}")

timer.log_time_llm_request()

progress_printer.update_timer_llm(ProgressPrinter.TimerEvent(start=True))

generator = llm.chat(user_input=text)

llm_message = ""
printed_stats = False
for token in generator:
if token is None:
continue

if timer.is_first_token:
timer.log_time_first_llm_token()
progress_printer.update_timer_llm(
ProgressPrinter.TimerEvent(num_milliseconds=timer.get_time_to_first_token()))
progress_printer.update_timer_tts(ProgressPrinter.TimerEvent(start=True))

progress_printer.update_llm_response(token)

llm_message += token

if synthesizer.input_streamable:
synthesizer.synthesize(token)

if not timer.before_first_audio:
progress_printer.update_timer_tts(
ProgressPrinter.TimerEvent(num_milliseconds=timer.get_time_to_first_audio()))
if not timer.before_first_audio and not printed_stats:
print()
progress_printer.print_timing_stats(
num_seconds_first_llm_token=timer.num_seconds_to_first_token(),
num_seconds_first_audio=timer.num_seconds_to_first_audio(),
)
printed_stats = True
print(f"Answering with {synthesizer} ...")

timer.increment_num_tokens()

Expand All @@ -166,23 +156,29 @@ def main(args: argparse.Namespace) -> None:
else:
synthesizer.synthesize(llm_message)

wait_start_time = time.time()
while timer.before_first_audio:
if time.time() - wait_start_time > MAX_WAIT_TIME_FIRST_AUDIO:
print(f"Waited for {MAX_WAIT_TIME_FIRST_AUDIO}s for first audio but did not receive any. Exiting")
break
wait_start_time = time.time()
while timer.before_first_audio:
if time.time() - wait_start_time > MAX_WAIT_TIME_FIRST_AUDIO:
print(
f"Waited for {MAX_WAIT_TIME_FIRST_AUDIO}s for first audio but did not receive any. Exiting")
break

progress_printer.update_timer_tts(
ProgressPrinter.TimerEvent(num_milliseconds=timer.get_time_to_first_audio()))
print()
progress_printer.print_timing_stats(
num_seconds_first_llm_token=timer.num_seconds_to_first_token(),
num_seconds_first_audio=timer.num_seconds_to_first_audio(),
)
print(f"Answering with {synthesizer} ...")

audio_output.wait_and_terminate()
progress_printer.stop()

num_interactions += 1

if num_interactions == 2:
break

print()

except KeyboardInterrupt:
pass

Expand Down
1 change: 0 additions & 1 deletion demo/llm/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
openai==1.17.0
pvcheetah==2.0.1
pvrecorder==1.2.2
rich==13.7.0
sounddevice==0.4.6
tiktoken==0.6.0
6 changes: 1 addition & 5 deletions demo/llm/src/user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pvrecorder import PvRecorder

from .transcriber import Transcriber, Transcribers
from .util import ListeningAnimation


class UserInputs(Enum):
Expand Down Expand Up @@ -46,8 +45,7 @@ def __init__(
self._recorder = PvRecorder(frame_length=self._transcriber.frame_length, device_index=audio_device_index)

def get_user_prompt(self) -> str:
animation = ListeningAnimation(message="Listening")
animation.start()
print("Listening ...")
if not self._recorder.is_recording:
self._recorder.start()

Expand All @@ -61,13 +59,11 @@ def get_user_prompt(self) -> str:
final_transcript = self._transcriber.flush()
transcript += final_transcript
self._recorder.stop()
animation.stop(message=self.STOP_MESSAGE)
if transcript == "":
transcript = "Hi, I'm trying to place an order on your webpage but I'm having trouble with the checkout process. Can you help me?"
return transcript
except Exception as e:
self._recorder.stop()
animation.stop(message=self.STOP_MESSAGE)
raise e


Expand Down
Loading

0 comments on commit 4ed95fe

Please sign in to comment.