summaryrefslogtreecommitdiff
path: root/external/plyer/platforms/ios/tts.py
diff options
context:
space:
mode:
Diffstat (limited to 'external/plyer/platforms/ios/tts.py')
-rw-r--r--external/plyer/platforms/ios/tts.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/external/plyer/platforms/ios/tts.py b/external/plyer/platforms/ios/tts.py
new file mode 100644
index 0000000..a711483
--- /dev/null
+++ b/external/plyer/platforms/ios/tts.py
@@ -0,0 +1,35 @@
+from pyobjus import autoclass, objc_str
+from pyobjus.dylib_manager import load_framework
+
+from plyer.facades import TTS
+
+load_framework('/System/Library/Frameworks/AVFoundation.framework')
+AVSpeechUtterance = autoclass('AVSpeechUtterance')
+AVSpeechSynthesizer = autoclass('AVSpeechSynthesizer')
+AVSpeechSynthesisVoice = autoclass('AVSpeechSynthesisVoice')
+
+
+class iOSTextToSpeech(TTS):
+ def __init__(self):
+ super(iOSTextToSpeech, self).__init__()
+ self.synth = AVSpeechSynthesizer.alloc().init()
+ self.voice = None
+
+ def _set_locale(self, locale="en-US"):
+ self.voice = AVSpeechSynthesisVoice.voiceWithLanguage_(objc_str(locale))
+
+ def _speak(self, **kwargs):
+ message = kwargs.get('message')
+
+ if(not self.voice):
+ self._set_locale()
+
+ utterance = \
+ AVSpeechUtterance.speechUtteranceWithString_(objc_str(message))
+
+ utterance.voice = self.voice
+ self.synth.speakUtterance_(utterance)
+
+
+def instance():
+ return iOSTextToSpeech()