示例#1
0
    def audio_stream_request_generator(self):
        """ Reads the sound from the ros-topic in an generator """
        query_input = dialogflow.QueryInput(audio_config=self.audio_config)
        # The first request contains the configuration.
        yield dialogflow.StreamingDetectIntentRequest(
            session=self.session,
            query_params=self.query_params,
            query_input=query_input)

        # Save data to audio file
        if self.save_audio_requests:
            filename = time.strftime("%Y-%m-%d %H:%M:%S",
                                     time.gmtime()) + ".wav"
            wf = wave.open(filename, "w")
            wf.setnchannels(1)
            wf.setsampwidth(2)
            wf.setframerate(16000)
        # Here we are reading small chunks of audio from a queue
        while not rospy.is_shutdown() and not self.cancel_stream_intent:
            try:
                chunk = self.audio_chunk_queue.popleft()
            except IndexError as e:
                # Wait for new sound data, should come within 0.1s since it is sent in 10Hz
                rospy.sleep(0.1)
                continue
            if self.save_audio_requests:
                wf.writeframes(chunk)

            # The later requests contains audio data.
            yield dialogflow.StreamingDetectIntentRequest(input_audio=chunk)
        rospy.loginfo("AVBRÖT STREAMING INTENT!!")
        if self.save_audio_requests:
            wf.close()
示例#2
0
    def request_generator(audio_config, audio_file_path):
        query_input = dialogflow.QueryInput(audio_config=audio_config)

        # The first request contains the configuration.
        yield dialogflow.StreamingDetectIntentRequest(
            session=session_path, query_input=query_input)

        # Here we are reading small chunks of audio data from a local
        # audio file.  In practice these chunks should come from
        # an audio input device.
        with open(audio_file_path, 'rb') as audio_file:
            while True:
                chunk = audio_file.read(4096)
                if not chunk:
                    break
                # The later requests contains audio data.
                yield dialogflow.StreamingDetectIntentRequest(input_audio=chunk)
示例#3
0
            def request_generator(audio_config):
                query_input = dialogflow.QueryInput(audio_config=audio_config)
                output_audio_config = dialogflow.OutputAudioConfig(
                    audio_encoding=dialogflow.OutputAudioEncoding.
                    OUTPUT_AUDIO_ENCODING_LINEAR_16)

                # The first request contains the configuration.
                yield dialogflow.StreamingDetectIntentRequest(
                    session=session_path,
                    query_input=query_input,
                    single_utterance=True,
                    output_audio_config=output_audio_config)

                while True:
                    chunk = self._buff.get()
                    if chunk is None:
                        print("chunk none")
                        return
                    if not self._isIntentDetect:
                        print("done intent")
                        return
                    yield dialogflow.StreamingDetectIntentRequest(
                        input_audio=chunk)