def decodeStream(self, session: DialogSession) -> Optional[ASRResult]:
        super().decodeStream(session)
        result = None

        with Stopwatch() as processingTime:
            with Recorder(self._timeout) as recorder:
                self.ASRManager.addRecorder(session.siteId, recorder)
                self._recorder = recorder
                streamContext = self._model.createStream()
                for chunk in recorder:
                    if not chunk:
                        break

                    self._model.feedAudioContent(
                        streamContext, np.frombuffer(chunk, np.int16))

                    result = self._model.intermediateDecode(streamContext)
                    self.partialTextCaptured(session=session,
                                             text=result,
                                             likelihood=1,
                                             seconds=0)

            text = self._model.finishStream(streamContext)
            self.end(session)

        return ASRResult(
            text=text,
            session=session,
            likelihood=1.0,
            processingTime=processingTime.time) if result else None
    def decodeStream(self, session: DialogSession) -> Optional[ASRResult]:
        super().decodeStream(session)

        recorder = Recorder(self._timeout, session.user, session.siteId)
        self.ASRManager.addRecorder(session.siteId, recorder)
        self._recorder = recorder
        with Stopwatch() as processingTime:
            with recorder as stream:
                audioStream = stream.audioStream()
                # noinspection PyUnresolvedReferences
                try:
                    requests = (types.StreamingRecognizeRequest(
                        audio_content=content) for content in audioStream)
                    responses = self._client.streaming_recognize(
                        self._streamingConfig, requests)
                    result = self._checkResponses(session, responses)
                except:
                    self.logWarning('Failed ASR request')

            self.end()

        return ASRResult(
            text=result[0],
            session=session,
            likelihood=result[1],
            processingTime=processingTime.time) if result else None
	def decodeStream(self, session: DialogSession) -> Optional[ASRResult]:
		super().decodeStream(session)

		result = None
		with Stopwatch() as processingTime:
			with Recorder(self._timeout) as recorder:
				self.ASRManager.addRecorder(session.siteId, recorder)
				self._decoder.start_utt()
				inSpeech = False
				for chunk in recorder:
					if self._timeout.isSet():
						break

					self._decoder.process_raw(chunk, False, False)
					if self._decoder.get_in_speech() != inSpeech:
						inSpeech = self._decoder.get_in_speech()
						if not inSpeech:
							self._decoder.end_utt()
							result = self._decoder.hyp() if self._decoder.hyp() else None
							break

				self.end(recorder, session)

		return ASRResult(
			text=result.hypstr.strip(),
			session=session,
			likelihood=self._decoder.hyp().prob,
			processingTime=processingTime.time
		) if result else None
Exemple #4
0
    def decodeStream(self, session: DialogSession) -> Optional[ASRResult]:
        super().decodeStream(session)
        result = None
        previous = ''

        with Stopwatch() as processingTime:
            with Recorder(self._timeout, session.user,
                          session.deviceUid) as recorder:
                self.ASRManager.addRecorder(session.deviceUid, recorder)
                self._recorder = recorder
                streamContext = self._model.createStream()
                for chunk in recorder:
                    if not chunk:
                        break

                    streamContext.feedAudioContent(
                        np.frombuffer(chunk, np.int16))

                    result = streamContext.intermediateDecode()
                    if result and result != previous:
                        previous = result
                        self.partialTextCaptured(session=session,
                                                 text=result,
                                                 likelihood=1,
                                                 seconds=0)

            text = streamContext.finishStream()
            self._triggerFlag.clear()
            self.end()

        return ASRResult(
            text=text,
            session=session,
            likelihood=1.0,
            processingTime=processingTime.time) if result else None
Exemple #5
0
    def decodeStream(self, session: DialogSession) -> Optional[ASRResult]:
        super().decodeStream(session)
        recorder = Recorder(self._timeout)
        self.ASRManager.addRecorder(session.siteId, recorder)
        with recorder as stream:
            audioStream = stream.audioStream()
            requests = (types.StreamingRecognizeRequest(audio_content=content)
                        for content in audioStream)
            responses = self._client.streaming_recognize(
                self._streamingConfig, requests)
            result = self._checkResponses(session, responses)

        self.end(recorder, session)

        return ASRResult(text=result[0],
                         session=session,
                         likelihood=result[1],
                         processingTime=10) if result else None
    def decodeStream(self, session: DialogSession) -> Optional[ASRResult]:
        super().decodeStream(session)

        result = None
        counter = 0
        with Stopwatch() as processingTime:
            with Recorder(self._timeout, session.user,
                          session.deviceUid) as recorder:
                self.ASRManager.addRecorder(session.deviceUid, recorder)
                self._recorder = recorder
                self._decoder.start_utt()
                inSpeech = False
                for chunk in recorder:
                    if self._timeout.isSet():
                        break

                    self._decoder.process_raw(chunk, False, False)
                    hypothesis = self._decoder.hyp()
                    if hypothesis:
                        counter += 1
                        if counter == 10:
                            self.partialTextCaptured(session,
                                                     hypothesis.hypstr,
                                                     hypothesis.prob,
                                                     processingTime.time)
                            counter = 0
                    if self._decoder.get_in_speech() != inSpeech:
                        inSpeech = self._decoder.get_in_speech()
                        if not inSpeech:
                            self._decoder.end_utt()
                            result = self._decoder.hyp() if self._decoder.hyp(
                            ) else None
                            break

                self.end()

        return ASRResult(
            text=result.hypstr.strip(),
            session=session,
            likelihood=self._decoder.hyp().prob,
            processingTime=processingTime.time) if result else None
Exemple #7
0
	def end(self, recorder: Recorder, session: DialogSession):
		self.MqttManager.mqttClient.unsubscribe(constants.TOPIC_AUDIO_FRAME.format(session.siteId))
		recorder.stopRecording()
		if self._timeoutTimer and self._timeoutTimer.is_alive():
			self._timeoutTimer.cancel()