Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions afkode/ios/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import os
import sys
import time
from pathlib import Path

import sound
import speech

# import sound
from afkode import api, utils


def speak(text: str) -> None:
def speak_old(text: str) -> None:
"""Say the text using iOS capability.

Args:
Expand All @@ -25,6 +27,33 @@ def speak(text: str) -> None:
time.sleep(0.1)


def speak(text: str) -> None:
"""Run text-to-speech on ios platform.

Args:
text: full text to be spoken.
"""
tts_base_path = Path(utils.get_base_path(), "data", "text_to_speech")
if not tts_base_path.exists():
tts_base_path.mkdir(parents=True)
logging.info(f">>>{text}")

# Attempt to use cache if couple of words or is a command
if len(text.split(" ")) <= 2 or text in utils.get_spoken_command_list():
tts_path = Path(tts_base_path, f"{text}.wav")
if not tts_path.exists():
api.google_tts(tts_path, text_input=text)
else:
tts_path = Path(tts_base_path, "latest.wav")
api.google_tts(tts_path, text_input=text)

player = sound.Player(str(tts_path))

player.play()
while player.playing:
time.sleep(0.1)


def play_blip() -> None:
"""Play a short sound to help notify of API speed."""
# sound.play_effect("ui:mouseclick1")
Expand All @@ -34,7 +63,6 @@ def play_blip() -> None:
if __name__ == "__main__":
# Basic speech testing. Can't run as module, so we import our library here
sys.path.append(os.path.realpath("../.."))
from afkode import utils

utils.setup_logging(log_level=logging.INFO)
speak("This is a test of the speech module")
29 changes: 26 additions & 3 deletions afkode/macos/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
from pydub import AudioSegment
from pydub.playback import play

from afkode import utils
from afkode import api, utils


def text_to_speech(sentence: str, idx: int) -> str:
"""Create a gTTS object.
"""Create a Google text to speech object.

Args:
sentence: input text to be spoken
Expand Down Expand Up @@ -91,7 +91,7 @@ def split_text(text: str) -> List[str]:
return splits


def speak(text: str) -> None:
def speak_old(text: str) -> None:
"""Run text-to-speech on non-ios platform.

Args:
Expand All @@ -117,6 +117,29 @@ def speak(text: str) -> None:
q.join()


def speak(text: str) -> None:
"""Run text-to-speech on non-ios platform.

Args:
text: full text to be spoken.
"""
tts_base_path = Path(utils.get_base_path(), "data", "text_to_speech")
if not tts_base_path.exists():
tts_base_path.mkdir(parents=True)
logging.info(f">>>{text}")

# Attempt to use cache if couple of words or is a command
if len(text.split(" ")) <= 2 or text in utils.get_spoken_command_list():
tts_path = Path(tts_base_path, f"{text}.wav")
if not tts_path.exists():
api.google_tts(tts_path, text_input=text)
else:
tts_path = Path(tts_base_path, "latest.wav")
api.google_tts(tts_path, text_input=text)

play(AudioSegment.from_file(tts_path))


def play_blip() -> None:
"""Play a short sound to help notify of API speed."""
file_name = Path("afkode", "macos", "blip.wav")
Expand Down
5 changes: 5 additions & 0 deletions afkode/prompts/goal/dnd_partial_summary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Your task is to create a summary of the following part of a dungeons and dragons session.

The setting for this one-shot Dungeons and Dragons campaign is a 1990s small-town aesthetic called Pin Tweaks. For context, there are three players who have recently taken a break from the playing session and want a recap of the interesting events and character interactions as they get back into the game.

You should mention what each of the characters has done (and which NPC characters they have engaged with.
1 change: 1 addition & 0 deletions afkode/prompts/output/limit_400.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Limit your total response to 400 words or less.
4 changes: 4 additions & 0 deletions afkode/prompts/output/ssml.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Your goal is to transform the following text into valid SSML Speech Synthesis Markup Language.
The aim is to prepare the text to be spoken aloud using text to voice.
Make the text as interesting as possible by using the prosody tag functions where it makes sense.
----