Compare commits

..

No commits in common. "7e9b19d328a854ca9990a0370bb57968d7bdb39b" and "8082123c586ae31bae1c8e4da4eaf651582696cf" have entirely different histories.

3 changed files with 3 additions and 58 deletions

View File

@ -2,6 +2,7 @@ import os
from typing import Optional, Sequence
from platypush.context import get_plugin
from platypush.message.event.assistant import MicMutedEvent, MicUnmutedEvent
from platypush.plugins import RunnablePlugin, action
from platypush.plugins.assistant import AssistantPlugin
from platypush.plugins.tts.picovoice import TtsPicovoicePlugin
@ -238,10 +239,11 @@ class AssistantPicovoicePlugin(AssistantPlugin, RunnablePlugin):
:param muted: Set to True or False.
"""
self._is_muted = muted
if self._assistant:
self._assistant.set_mic_mute(muted)
super()._on_mute_changed(muted)
self._send_event(MicMutedEvent if muted else MicUnmutedEvent)
@action
def toggle_mute(self, *_, **__):

View File

@ -19,7 +19,6 @@ manifest:
- python-numpy
- python-sounddevice
pip:
- num2words
- numpy
- sounddevice
package: platypush.plugins.tts

View File

@ -1,6 +1,4 @@
import logging
import os
import re
from threading import RLock
from typing import Optional
@ -13,56 +11,6 @@ from platypush.plugins import action
from platypush.plugins.tts import TtsPlugin
class TextConversionUtils:
"""
Utility class to convert text to a format that is supported by the Orca TTS
engine.
This pre-processing step is necessary until the issue is fixed:
https://github.com/Picovoice/orca/issues/10.
"""
_logger = logging.getLogger(__name__)
_number_re = re.compile(r'(([0-9]+)|([0-9]+\.[0-9]+)|([0-9]+\,[0-9]+))')
_conversions_map = {
(re.compile(r'[(){}\[\]<>]'), ','),
(re.compile(r'[:;]'), '.'),
(re.compile(r'[@#]'), ' at '),
(re.compile(r'[$]'), ' dollar '),
(re.compile(r'[%]'), ' percent '),
(re.compile(r'[&]'), ', and'),
(re.compile(r'[+]'), ' plus '),
(re.compile(r'[=]'), ' equals '),
(re.compile(r'[|]'), ' or '),
(re.compile(r'[~]'), ' tilde '),
(re.compile(r'[`\'"]'), ': quote:'),
(re.compile(r'[*]'), ' star '),
(re.compile(r'[\\/]'), ' slash '),
(re.compile(r'[_]'), ' underscore '),
}
@classmethod
def _convert_digits(cls, text: str) -> str:
try:
from num2words import num2words
except ImportError:
cls._logger.warning('num2words is not installed, skipping digit conversion')
return text
while match := cls._number_re.search(text):
number = match.group(1).replace(',', '')
text = text.replace(number, num2words(int(number)))
return text
@classmethod
def convert(cls, text: str) -> str:
for pattern, replacement in TextConversionUtils._conversions_map:
text = pattern.sub(replacement, text)
return cls._convert_digits(text)
class TtsPicovoicePlugin(TtsPlugin):
"""
This TTS plugin enables you to render text as audio using `Picovoice
@ -160,11 +108,7 @@ class TtsPicovoicePlugin(TtsPlugin):
:param model_path: Path of the TTS model file (default: use the default
configured model).
"""
# This is a temporary workaround until this issue is fixed:
# https://github.com/Picovoice/orca/issues/10.
text = TextConversionUtils.convert(text)
orca = self.get_orca(model_path=model_path)
if output_file:
orca.synthesize_to_file(
text, os.path.expanduser(output_file), speech_rate=speech_rate