Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--speak_messages TTS updated cross platform #1233

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 15 additions & 15 deletions interpreter/terminal_interface/terminal_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import re
import subprocess
import time
import pyttsx3
import threading

from ..core.utils.scan_code import scan_code
from ..core.utils.system_debug_info import system_info
Expand Down Expand Up @@ -43,7 +45,6 @@
# If they don't have readline, that's fine
pass


def terminal_interface(interpreter, message):
# Auto run and offline (this.. this isnt right) don't display messages.
# Probably worth abstracting this to something like "debug_cli" at some point.
Expand Down Expand Up @@ -197,20 +198,19 @@ def terminal_interface(interpreter, message):
interpreter.computer.os.notify(sanitized_message)

# Speak message aloud
if platform.system() == "Darwin" and interpreter.speak_messages:
if voice_subprocess:
voice_subprocess.terminate()
voice_subprocess = subprocess.Popen(
[
"osascript",
"-e",
f'say "{sanitized_message}" using "Fred"',
]
)
else:
pass
# User isn't on a Mac, so we can't do this. You should tell them something about that when they first set this up.
# Or use a universal TTS library.
def speak_text(text):
engine = pyttsx3.init()
engine.setProperty('rate', 150)
engine.setProperty('volume', 0.9)
engine.say(text)
engine.runAndWait()

def speak_async(text):
thread = threading.Thread(target=speak_text, args=(text,))
thread.start()

if interpreter.speak_messages:
speak_async(sanitized_message)

# Assistant code blocks
elif chunk["role"] == "assistant" and chunk["type"] == "code":
Expand Down
58 changes: 49 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tiktoken = "^0.6.0"
aifs = "^0.0.15"
platformdirs = "^4.2.0"
pydantic = "^2.6.4"
pyttsx3 = "^2.90"

# Optional [os] dependencies
opencv-python = { version = "^4.8.1.78", optional = true }
Expand Down