Can't install pyttsx3 module
I install stash, and after in stash console try:
pip install pyttsx3
Running setup file ...
PermissionError(1, 'Operation not permitted')
Failed to run setup.py
Fall back to directory guessing ...
Error: Cannot locate packages. Manual installation required.
When installed wikipedia all was ok.
Please help solve.
how can i print all availible voices?
import objc_util import re class SpeechModule(object): def __init__(self): self.__AVSpeechUtterance = objc_util.ObjCClass('AVSpeechUtterance') self.__AVSpeechSynthesizer = objc_util.ObjCClass('AVSpeechSynthesizer') self.__AVSpeechSynthesisVoice = objc_util.ObjCClass('AVSpeechSynthesisVoice') self.__synthesizer = self.__AVSpeechSynthesizer.new() def get_synthesis_languages(self) -> list: return self.__AVSpeechSynthesisVoice.speechVoices() def say(self, msg: str, language: objc_util.ObjCInstance, rate=0.5): utterance = self.__AVSpeechUtterance.speechUtteranceWithString_(msg) utterance.rate = rate utterance.voice = voice utterance.useCompactVoice = False self.__synthesizer.speakUtterance_(utterance) def is_speaking(self) -> bool: return self.__synthesizer.isSpeaking() def is_paused(self) -> bool: return self.__synthesizer.isPaused() def pause(self) -> bool: return self.__synthesizer.pauseSpeakingAtBoundary_(True) def stop(self) -> bool: return self.__synthesizer.stopSpeakingAtBoundary_(True) def continue_speaking(self): self.__synthesizer.continueSpeaking()
Here is an example how to use it
import time speech_ = SpeechModule() available_voices = speech_.get_synthesis_languages() us_english_voices = tuple(filter(lambda voice: "en-US" in str(voice), available_voices)) voice = us_english_voices speech_.say('Hello friend! how are you?', voice, 0.3) time.sleep(1) speech_.stop() print(speech_.is_speaking()) speech_.say("nevermind", voice)
@sulcud 👍 perfect except the fact to include me in a gurus list 😢
For some reason I can’t make that pause function to work correctly,
Parameter of pauseSpeakingAtBoundary_ is not a Boolean but an integer, see AVSpeechBoundary , try 0=Immediately instead ofTrue
@cvp, you are right, using 0 fixes it, did you find anyway to fix the false positives that is_paused and is_speaking functions return?
@sulcud I don't have tested your code thus I didn't know there were some problems, except this one you described. I'll try later, sorry
@sulcud First, parameter of stopSpeakingAtBoundary_ is also integer...
did you find anyway to fix the false positives that is_paused and is_speaking functions return?
Haven't tried, but often objc_util.on_main_thread fixes problems like is_paused not reporting correct no values.
Note is_speaking will return true even if paused...
@JonB nothing changed for is_speaking, as you did foresee
Returns YES if the synthesizer is speaking or has utterances enqueued to speak, even if it is currently paused. Returns NO if the synthesizer has finished speaking all utterances in its queue or if it has not yet been given an utterance to speak.
So if you want to know when speaking stops, one would want to check if not
Because of threading and such, it might be more reliable to implement the delegate, and then keep track of state within the delegate object, that can then be queried in python code.
@sulcud, looking at this putting a wrapper around the delegate as @JonB suggests looks like the best way to get fine control over the speech, being able to highlight individual words as they are spoken etc.
Such a wrapper could also include synchronous methods, so that it would be easy to just say something and move on after the talking is done.
I was remove speech module in my iOS. How to recover???
I think that erasing a Pythonista build-in module is not possible, remember that python has a weird importing system so if you have a script/folder called speech in the same folder of your main script maybe you are importing it instead of the build in one. (python import order is: current dir, ... , site-packages, build-in) but If that is not the case, I think a fresh install of Pythonista could work
@sulcud fresh install doesn't helped. I was delete speech module before over stash(((. Now i can't recover.
Make sure you don't have a speech.py in site-packages, or in the same folder as the main script you are running. Also make sure you don't have any folders called speech inside site-packages, that includes an init file.
As a check, in the console, try
If that fails, look at the traceback to show you what failed, which should include a path to the module it was trying to import.
You can also try
import speech import inspect print(inspect.getfile(speech))
Either you will get an error module 'speech' (built-in)> is a built-in module
Either you will get its path if another speech module is imported
get an error module 'speech' (built-in)> is a built-in module
@lyubomyr83 thus, you did not remove it...
@lyubomyr83 why do you think you deleted the speech module? What error do you get when you try to use it?
Or, are you talking the SpeechModule script that was shared?
In that case, just copy the code again, paste into the editor, and name it something other than speech...