當前位置: 首頁>>代碼示例>>Python>>正文


Python speech_recognition.AudioData方法代碼示例

本文整理匯總了Python中speech_recognition.AudioData方法的典型用法代碼示例。如果您正苦於以下問題:Python speech_recognition.AudioData方法的具體用法?Python speech_recognition.AudioData怎麽用?Python speech_recognition.AudioData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在speech_recognition的用法示例。


在下文中一共展示了speech_recognition.AudioData方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: convert

# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import AudioData [as 別名]
def convert(audio_data):
    if isinstance(audio_data, types.GeneratorType):
        def generate(audio):
            yield BingSpeechAPI.get_wav_header()
            for a in audio:
                yield a
        data = generate(audio_data)
    else:
        data = BingSpeechAPI.to_wav(audio_data)
    audio = sr.AudioData(''.join(data), 16000, 2)
    return audio 
開發者ID:respeaker,項目名稱:respeaker_python_library,代碼行數:13,代碼來源:SpeechRecognition_translator.py

示例2: test_live

# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import AudioData [as 別名]
def test_live(message):
    speech = sr.AudioData(base64.b64decode(message['data']),message['sample_rate'],message['sample_width'])
    value = r.recognize_google(speech,language='ms-MY')
    emit('speech_update', {'text': value},broadcast=True) 
開發者ID:huseinzol05,項目名稱:Gather-Deployment,代碼行數:6,代碼來源:server.py

示例3: recognize_from_api

# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import AudioData [as 別名]
def recognize_from_api(audio, api, name='API', safe=True, **kwargs):
    if not isinstance(audio, sr.AudioData):
        with sr.AudioFile(audio) as source:
            audio = r.record(source)
    try:
        return api(audio, **kwargs)
    except sr.UnknownValueError as e:
        if not safe:
            raise e
        return "\t%s could not understand audio" % name
    except sr.RequestError as e:
        if not safe:
            raise e
        return "\tCould not request results from %s \
    service; {0}" % (name, e) 
開發者ID:igormq,項目名稱:asr-study,代碼行數:17,代碼來源:apis.py

示例4: __init__

# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import AudioData [as 別名]
def __init__(self):
        # format of input audio data
        self.sample_rate = rospy.get_param("~sample_rate", 16000)
        self.sample_width = rospy.get_param("~sample_width", 2L)
        # language of STT service
        self.language = rospy.get_param("~language", "ja-JP")
        # ignore voice input while the robot is speaking
        self.self_cancellation = rospy.get_param("~self_cancellation", True)
        # time to assume as SPEAKING after tts service is finished
        self.tts_tolerance = rospy.Duration.from_sec(
            rospy.get_param("~tts_tolerance", 1.0))

        self.recognizer = SR.Recognizer()

        self.tts_action = None
        self.last_tts = None
        self.is_canceling = False
        if self.self_cancellation:
            self.tts_action = actionlib.SimpleActionClient(
                "sound_play", SoundRequestAction)
            if self.tts_action.wait_for_server(rospy.Duration(5.0)):
                self.tts_timer = rospy.Timer(rospy.Duration(0.1), self.tts_timer_cb)
            else:
                rospy.logerr("action '%s' is not initialized." % rospy.remap_name("sound_play"))
                self.tts_action = None

        self.pub_speech = rospy.Publisher(
            "speech_to_text", SpeechRecognitionCandidates, queue_size=1)
        self.sub_audio = rospy.Subscriber("audio", AudioData, self.audio_cb) 
開發者ID:furushchev,項目名稱:respeaker_ros,代碼行數:31,代碼來源:speech_to_text.py

示例5: audio_cb

# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import AudioData [as 別名]
def audio_cb(self, msg):
        if self.is_canceling:
            rospy.loginfo("Speech is cancelled")
            return
        data = SR.AudioData(msg.data, self.sample_rate, self.sample_width)
        try:
            rospy.loginfo("Waiting for result %d" % len(data.get_raw_data()))
            result = self.recognizer.recognize_google(
                data, language=self.language)
            msg = SpeechRecognitionCandidates(transcript=[result])
            self.pub_speech.publish(msg)
        except SR.UnknownValueError as e:
            rospy.logerr("Failed to recognize: %s" % str(e))
        except SR.RequestError as e:
            rospy.logerr("Failed to recognize: %s" % str(e)) 
開發者ID:furushchev,項目名稱:respeaker_ros,代碼行數:17,代碼來源:speech_to_text.py


注:本文中的speech_recognition.AudioData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。