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.


    File where the speech is saved

    Pythonista
    2
    74
    14149
    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.
    • Python567
      Python567 last edited by

      I found in the documentation a example code:

      
      import speech
      import sound
      import dialogs
      
      # Record an audio file using sound.Recorder:
      recorder = sound.Recorder('speech.m4a')
      recorder.record()
      # Continue recording until the 'Finish' button is tapped:
      dialogs.alert('Recording...', '', 'Finish', hide_cancel_button=True)
      recorder.stop()
      try:
          result = speech.recognize('speech.m4a')
          print('=== Details ===')
          print(result)
          print('=== Transcription ===')
          print(result[0][0])
      
      except RuntimeError as e:
          print('Speech recognition failed: %s' % (e,))
      
      

      On line 12 ther is a speech.m4a is that the File where the Speech is saved and if yes can I delete the file and where is this one?

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

        @Python567 sound.recorder writes the file and speech.recognize reads the file.
        It is in the same folder as the script. And of course you can delete it

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

          @cvp ok, thanks for the fast answer🙂

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

            @cvp an other question: Can the speech or sound module listen and know what I say if he listen during I ask what I say?

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

              @Python567 said:

              Can the speech or sound module listen and know what I say if he listen during I ask what I say?

              Not understood/non compris/no comprendo/no capito....

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

                @cvp so, the modul listen to me every time. Can I find out what I say if the modul don‘t stop to listen to me?

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

                  @Python567 the sound module records what you say, it does not really listen to you, and that until you stop it.

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

                    ok, so if I want that the module check all five minutes what I say, I must stop it every five minutes to check it`?

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

                      @Python567 yes but I wonder if @JonB didn't write a script to do this in real time...

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

                        @cvp @JonB write this module

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

                          @Python567 you could read this topic but don't hope much help

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

                            @cvp I have a code that aks all 5 seconds if I say something. But I get an error after the print is finish.

                            import time
                            import sound
                            import speech
                            
                            timestamp = time.time() 
                            
                            recorder = sound.Recorder('speech.m4a')
                            recorder.record()
                            	
                            while True:
                            	
                            		if timestamp - time.time() <= -5:
                            			recorder.stop()
                            			result = speech.recognize('speech.m4a', 'de_DE')
                            	
                            			
                            			if result[0][0] == 'Hallo':
                            				print('Du hast hallo gesagt')
                            				
                            				recorder.record()
                            cvp 1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @Python567 last edited by

                              @Python567 two modifs

                              import time
                              import sound
                              import speech
                              
                              timestamp = time.time() 
                              
                              recorder = sound.Recorder('speech.m4a')
                              recorder.record()
                                  
                              while True:
                                      time.sleep(1)
                                      if timestamp - time.time() <= -5:
                                          recorder.stop()
                                          result = speech.recognize('speech.m4a', 'de_DE')
                                  
                                          
                                          if result[0][0] == 'Hallo':
                                              print('Du hast hallo gesagt')
                                              timestamp = time.time() 
                                              recorder.record()
                              
                              1 Reply Last reply Reply Quote 1
                              • Python567
                                Python567 last edited by

                                @cvp thanks, that‘s great

                                cvp 1 Reply Last reply Reply Quote 0
                                • Python567
                                  Python567 last edited by Python567

                                  @cvp is it normal that my Pythonista crash sometimes? I have a skript with over 18 000 lines. Is that a problem? And how can I update a button every second for my clock?

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

                                    @Python567 try

                                    import ui
                                    import datetime
                                    
                                    class MyView(ui.View):
                                    	def __init__(self):
                                    		self.frame = (0,0,400,400)
                                    		self.background_color = 'white'
                                    		b = ui.Button(name='b')
                                    		b.border_width = 1
                                    		b.border_color = 'blue'
                                    		b.frame = (10,10,250,20)
                                    		self.add_subview(b)
                                    		self.update_interval = 1
                                    	def update(self):
                                    		self['b'].title = str(datetime.datetime.now())
                                    
                                    v = MyView()
                                    v.present('sheet')
                                    
                                    1 Reply Last reply Reply Quote 0
                                    • cvp
                                      cvp @Python567 last edited by

                                      @Python567 said:

                                      is it normal that my Pythonista crash sometimes?

                                      It can be normal if you script uses a lot of memory and you re-run it several times without clearing it.
                                      It happens frequently that I have to kill Pythonista and restart it when I use a big script or a script using a lot of images, by example.

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

                                        @Python567 other example, try it

                                        import ui
                                        import datetime
                                        from math import pi,cos,sin
                                        
                                        class ClockButton(ui.View):           
                                        	def __init__(self, seconds=True, *args, **kwargs):
                                        		super().__init__(*args, **kwargs)
                                        		self.seconds = seconds
                                        		self.background_color = 'white'
                                        		b = ui.Button(name='clock')
                                        		b.frame = (0,0,self.width,self.height)
                                        		b.corner_radius = self.width/2
                                        		b.border_color = 'black'
                                        		b.border_width = 1
                                        		b.bg_color = 'lightgray'
                                        		b.title = ''
                                        		b.tint_color = 'red'
                                        		b.background_image = None
                                        		self.add_subview(b)
                                        
                                        		self.update_interval = 1 if self.seconds else 60
                                        	def update(self):
                                        		t = datetime.datetime.utcnow()
                                        		tick = -2 * pi / 60.0
                                        		seconds = t.second + t.microsecond/1000000.0
                                        		minutes = t.minute + seconds/60.0
                                        		hours = (t.hour % 12) + minutes/60.0
                                        		r = self.width/2
                                        		with ui.ImageContext(r * 2, r * 2) as ctx:
                                        			pthc = ui.Path.oval(r*0.9,r*0.9,r*0.2,r*0.2)
                                        			ui.set_color('black')
                                        			pthc.fill()
                                        			pth = ui.Path()
                                        			ui.set_color('black')
                                        			pth.line_width = 2
                                        			# hours
                                        			lh = 0.6												# length of hours hand
                                        			ah = -pi/2 + hours*(2*pi/12)		# angle  of hours hand
                                        			pth.move_to(r,r)
                                        			pth.line_to(r*(1+lh*cos(ah)),r*(1+lh*sin(ah)))
                                        			# minutes
                                        			lm = 0.9												# length of minutes hand
                                        			am = -pi/2 + minutes*(2*pi/60)	# angle  of minutes hand		
                                        			pth.move_to(r,r)
                                        			pth.line_to(r*(1+lm*cos(am)),r*(1+lm*sin(am)))
                                        			pth.stroke()
                                        			# seconds
                                        			if self.seconds:
                                        				lt = 0.9												# length of seconds hand
                                        				at = -pi/2 + seconds*(2*pi/60)	# angle  of seconds hand
                                        				pths = ui.Path()
                                        				ui.set_color('red')
                                        				pths.move_to(r,r)
                                        				pths.line_to(r*(1+lt*cos(at)),r*(1+lt*sin(at)))
                                        				pths.stroke()
                                        			ui_image = ctx.get_image()
                                        		self['clock'].background_image = ui_image
                                        
                                        
                                        v = ui.View()
                                        v.background_color = 'white'
                                        v.frame = (0,0,400,400)
                                        clock = ClockButton(frame=(10,10,32,32))
                                        v.add_subview(clock)
                                        v.present('sheet')
                                        
                                        1 Reply Last reply Reply Quote 0
                                        • Python567
                                          Python567 last edited by

                                          @cvp wow, the second example is better 👍. And if I want the numbers, where can I add them?

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

                                            @Python567 said:

                                            the numbers, where can I add them

                                            Do you mind the numbers 1 to 12 on the circle?

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