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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ numpy
torch
transformers
requests
pyspellchecker
28 changes: 28 additions & 0 deletions speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,32 @@

from sugar3.speech import GstSpeechPlayer

# Spell checker for child users
try:
from spellchecker import SpellChecker
SPELLCHECKER_AVAILABLE = True
except ImportError:
SPELLCHECKER_AVAILABLE = False


def correct_spelling(text, lang='en'):
"""Correct invented spellings for child users before TTS processing."""
if not SPELLCHECKER_AVAILABLE:
return text
try:
spell = SpellChecker(language=lang)
Comment on lines +38 to +44
words = text.split()
corrected = []
for word in words:
correction = spell.correction(word)
if correction and correction != word:
Comment on lines +45 to +49
corrected.append(correction)
else:
corrected.append(word)
return ' '.join(corrected)
except Exception:
return text
Comment on lines +54 to +55

# Kokoro TTS imports
try:
from kokoro import KPipeline
Expand Down Expand Up @@ -365,6 +391,8 @@ def _stream_kokoro_audio(self, text, voice):

def speak(self, status, text):
self.make_pipeline()
# Correct invented spellings for child users before TTS
text = correct_spelling(text)

Comment on lines 392 to 396
if KOKORO_AVAILABLE and self.kokoro_pipeline:
logger.debug('Using Kokoro TTS: voice=%s text=%s' % (self.current_kokoro_voice, text))
Expand Down
Loading