Active Topics

 


Reply
Thread Tools
Posts: 83 | Thanked: 64 times | Joined on May 2012 @ Spain
#1
I would make a python script to recognize certain words. For example, I say "dog" and print the number 1. What says "cat" and print the number 2. Is it possible in maemo? Can anyone leave me a code snippet?
 
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#2
I'm not sure about Python, but search for PocketSphinx, it's an open source speech recognition engine, and it might have python bindings somewhere.
 
woody14619's Avatar
Posts: 1,455 | Thanked: 3,309 times | Joined on Dec 2009 @ Rochester, NY
#3
You may want to also look at this thread.
__________________
Maemo Council Member: May 2012 - November 2012
Hildon Foundation founding member.
Hildon Foundation Board of Directors: March 2013 - Jan 15, 2014
 
Posts: 83 | Thanked: 64 times | Joined on May 2012 @ Spain
#4
Thank you both. taixzo has happened to me this script. For now it does not work, but I'm on it.

Code:
 #!/usr/bin/python

import math
import gobject
import pygst
pygst.require('0.10')
gobject.threads_init()
import gst


class Example:
	def __init__(self):
		self.init_gst()


	def init_gst(self):
		"""Initialize the speech components"""
		self.pipeline = gst.parse_launch('pulsesrc ! audioconvert ! audioresample '
										 + '! vader name=vad auto-threshold=true '
										 + '! pocketsphinx name=asr ! fakesink')
		asr = self.pipeline.get_by_name('asr')
		asr.connect('partial_result', self.asr_partial_result)
		asr.connect('result', self.asr_result)
		asr.set_property('configured', True)

		bus = self.pipeline.get_bus()
		bus.add_signal_watch()
		bus.connect('message::application', self.application_message)

		self.pipeline.set_state(gst.STATE_PAUSED)

	def asr_partial_result(self, asr, text, uttid):
		"""Forward partial result signals on the bus to the main thread."""
		struct = gst.Structure('partial_result')
		struct.set_value('hyp', text)
		struct.set_value('uttid', uttid)
		asr.post_message(gst.message_new_application(asr, struct))

	def asr_result(self, asr, text, uttid):
		"""Forward result signals on the bus to the main thread."""
		struct = gst.Structure('result')
		struct.set_value('hyp', text)
		struct.set_value('uttid', uttid)
		asr.post_message(gst.message_new_application(asr, struct))

	def application_message(self, bus, msg):
		"""Receive application messages from the bus."""
		msgtype = msg.structure.get_name()
		if msgtype == 'partial_result':
			self.partial_result(msg.structure['hyp'], msg.structure['uttid'])
		elif msgtype == 'result':
			self.final_result(msg.structure['hyp'], msg.structure['uttid'])
			self.pipeline.set_state(gst.STATE_PAUSED)
			
	def partial_result(self, hyp, uttid):
		"""Delete any previous selection, insert text and select it."""
		# All this stuff appears as one single action
		print "Partial Result:", hyp
		
	def final_result(self, hyp, uttid):
	  """Insert the final result."""
	  # All this stuff appears as one single action
	  if hyp in ('start', 'power', 'red', 'green', 'yellow', 'blue')
	  	print "Final Result:", hyp
	  else:
	  	print "Not a recognized word."

if __name__=='__main__':

	app = Example()
	loop = gobject.MainLoop()
	gobject.threads_init()
	loop.run()
 
Reply


 
Forum Jump


All times are GMT. The time now is 19:52.