omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Can't install pyttsx3 module

    Pythonista
    6
    33
    17310
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • lyubomyr83
      lyubomyr83 last edited by lyubomyr83

      I install stash, and after in stash console try:
      pip install pyttsx3

      I receive
      ........
      ........
      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.

      1 Reply Last reply Reply Quote 0
      • sulcud
        sulcud last edited by

        This is not a solution for the installation but maybe it can help you, Pythonista has an already TTS module called “speech” and it works well

        
        import speech
        
        speech.say('hello')
        
        
        lyubomyr83 2 Replies Last reply Reply Quote 0
        • lyubomyr83
          lyubomyr83 last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • lyubomyr83
            lyubomyr83 @sulcud last edited by

            @sulcud
            In iOS 12 russian language work well. But in iOS 13 russian words pronounce terrible with english mix. What's wrong in iOS13?

            1 Reply Last reply Reply Quote 0
            • sulcud
              sulcud last edited by sulcud

              I don’t speak Russian so I can’t confirm is the Russian pronunciation Is wrong, but maybe you are running the “say” function with the language “en-US”; this function has this parameters:

              text -> text you want to say
              language -> (optional) the language that you want to speak with
              rate -> (optional) the speed of the voice

              Maybe you are trying this, I don’t know

              import speech
              
              speech.say(some_russian_text)
              

              You should try

              import speech
              
              speech.say("привет друг", "ru-RU")
              
              lyubomyr83 2 Replies Last reply Reply Quote 0
              • cvp
                cvp last edited by

                If not yet ok, you could try speech via ObjectiveC

                1 Reply Last reply Reply Quote 0
                • lyubomyr83
                  lyubomyr83 @sulcud last edited by

                  @sulcud
                  Thank's again. Setting "ru-RU" working good in iOS13.

                  def say(text):

                  settings = read_settings()
                  
                  if settings["sound"] == 'yes':
                  	# windows
                  	if os.name == 'nt':
                  		engine = pyttsx3.init()
                  
                  		en_voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0"
                  		ru_voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_RU-RU_IRINA_11.0"
                  
                  		# use russian sound
                  		engine.setProperty('voice', ru_voice_id)
                  		engine.say(text)
                  		engine.runAndWait()
                  	# iOS, Android
                  	elif os.name == 'posix':
                  		speech.say(text, "ru-RU")
                  	else:
                  		pass
                  
                  1 Reply Last reply Reply Quote 0
                  • lyubomyr83
                    lyubomyr83 @sulcud last edited by

                    @sulcud
                    Maybe you know how to change default voice from female to male?
                    And how can i print all availible voices?

                    1 Reply Last reply Reply Quote 0
                    • ccc
                      ccc last edited by

                      @lyubomyr83 said:

                      how can i print all availible voices?

                      https://forum.omz-software.com/topic/4706/how-to-use-speech-say-in-different-voice/2

                      1 Reply Last reply Reply Quote 0
                      • sulcud
                        sulcud last edited by sulcud

                        @lyubomyr83, I made this class to make it easier to work with the reference @ccc is pointing to, all could be done thanks to the work of @JonB

                        
                        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[0]
                        
                        speech_.say('Hello friend! how are you?', voice, 0.3)
                        
                        time.sleep(1)
                        speech_.stop()
                        print(speech_.is_speaking())
                        speech_.say("nevermind", voice)
                        

                        For some reason I can’t make that pause function to work correctly, anyway, it is an idea for your project and maybe my class could be buggy, so objc gurus invocation (@cvp @mikael @JonB @ccc )

                        cvp 2 Replies Last reply Reply Quote 0
                        • cvp
                          cvp @sulcud last edited by

                          @sulcud 👍 perfect except the fact to include me in a gurus list 😢

                          1 Reply Last reply Reply Quote 0
                          • cvp
                            cvp @sulcud last edited by cvp

                            @sulcud said:

                            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

                            1 Reply Last reply Reply Quote 0
                            • sulcud
                              sulcud last edited by sulcud

                              @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?

                              cvp mikael 4 Replies Last reply Reply Quote 0
                              • cvp
                                cvp @sulcud last edited by cvp

                                @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

                                1 Reply Last reply Reply Quote 0
                                • cvp
                                  cvp @sulcud last edited by

                                  @sulcud First, parameter of stopSpeakingAtBoundary_ is also integer...

                                  1 Reply Last reply Reply Quote 0
                                  • cvp
                                    cvp @sulcud last edited by

                                    @sulcud said:

                                    did you find anyway to fix the false positives that is_paused and is_speaking functions return?

                                    No, sorry

                                    1 Reply Last reply Reply Quote 0
                                    • JonB
                                      JonB last edited by

                                      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...

                                      cvp 1 Reply Last reply Reply Quote 0
                                      • cvp
                                        cvp @JonB last edited by

                                        @JonB nothing changed for is_speaking, as you did foresee

                                        1 Reply Last reply Reply Quote 0
                                        • JonB
                                          JonB last edited by

                                          Discussion
                                          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 speaking, or speaking and paused.

                                          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.

                                          1 Reply Last reply Reply Quote 1
                                          • mikael
                                            mikael @sulcud last edited by

                                            @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.

                                            1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors