def __init__(self, language = "en_GB"): dialog_context_xml_path=os.path.join(os.path.dirname(__file__), '../../homodeus_external/xml_folder/dialog_context.xml') self.dialog_context = ET.parse(dialog_context_xml_path).getroot() self.language = language # initialisation of global class variables self.selected_context = "" self.repeat = 0 self.relevant_info = "" self.reach_deadline = False self.timer = None self.dialoguing_now = False self.dialog_state = Dialog_state.begin # the code works differently if it's run on the robot or not param_name = rospy.search_param('on_robot') self.on_robot = rospy.get_param(param_name,False) # Goal input self.input_bhvr_goal_context = rospy.Subscriber("/bhvr_input_goal_dialContext",data_class=String, callback=self.set_context_Cb,queue_size=10) # Output self.output_bhvr_result = rospy.Publisher("/bhvr_output_res_dialBool", Bool, queue_size=10) self.output_bhvr_relevant = rospy.Publisher("/bhvr_output_res_dialRelevant", String, queue_size=10) # dialog only use tts_server when it's run on the robot if self.on_robot: self.connect_to_tts_server() self.speech_recognizer = sr.SpeechRecognizer()
def listen_commands(self): text = "How I can help You." speech = Speech() speech.create_voice(text) r = SpeechRecognizer() command = (r.recognize()).lower() print 'Recognized command: {0}'.format(command) if 'weatcher' in command: self.command_weatcher() if 'autopilot' in command: self.command_autopilot() if 'dance' in command: self.command_dance() if 'exterminate' in command: self.command_exterminate()
def __init__(self, language='en-US'): """ This method initializes the perception module by initializing the output topic and the Speech_recognition object Arguments --------- language : string The language used for the speech recognition. By default its value is set to american english. """ #The output of the module self.output_perc = rospy.Publisher("/proc_output_listenText", String, queue_size=10) self.language = language self.speech_recognizer = sr.SpeechRecognizer()
def listen_text(self): r = SpeechRecognizer() text = (r.recognize()).lower() print 'Recognized text: {0}'.format(text) if 'shadow' in text: self.listen_commands()
import os import subprocess import time import logging import uuid from speech_recognizer import SpeechRecognizer from punctuator import Punctuator from number_utils.text2numbers import TextToNumbers speech_recognizer = SpeechRecognizer() punctuator = Punctuator(model_path="data/punctuator") text2numbers = TextToNumbers() class FileHandler: @staticmethod def get_recognized_text(blob): try: filename = str(uuid.uuid4()) os.makedirs('./records', exist_ok=True) new_record_path = os.path.join('./records', filename + '.webm') blob.save(new_record_path) new_filename = filename + '.wav' converted_record_path = FileHandler.convert_to_wav( new_record_path, new_filename) response_models_result = FileHandler.get_models_result( converted_record_path) return 0, new_filename, response_models_result except Exception as e: logging.exception(e) return 1, None, str(e)
def __init__(self, audio_stream): self.speech_recognizer = SpeechRecognizer(audio_stream) self.natural_language_processor = NaturalLanguageProcessor()