第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復(fù)無異常迭代請求!問題

如何修復(fù)無異常迭代請求!問題

白衣非少年 2022-06-22 15:50:23
我對語音識別主題很陌生我正在做一個項目,我可以在工作區(qū)中找到 Pepper bot 的一些用例。與 Pepper 一起玩,我們發(fā)現(xiàn)了它的語音識別能力的一些問題。我發(fā)現(xiàn)我們可以嘗試將它與外部引擎連接起來,我從 GCP 中選擇了 DialogFlow。也因為我發(fā)現(xiàn)了一些與該服務(wù)的集成。我使用了這個項目的代碼import tracebackfrom naoqi import qi# [START dialogflow_detect_intent_streaming]def detect_intent_stream(project_id, session_id, audio_file_path,                         language_code,ip):    """Returns the result of detect intent with streaming audio as input.    Using the same `session_id` between requests allows continuation    of the conversation."""    import dialogflow_v2 as dialogflow    session_client = dialogflow.SessionsClient()    # Note: hard coding audio_encoding and sample_rate_hertz for simplicity.    audio_encoding = dialogflow.enums.AudioEncoding.AUDIO_ENCODING_LINEAR_16    sample_rate_hertz = 44100    session_path = session_client.session_path(project_id, session_id)    print('Session path: {}\n'.format(session_path))    def request_generator(audio_config, audio_file_path):        query_input = dialogflow.types.QueryInput(audio_config=audio_config)        # The first request contains the configuration.        yield dialogflow.types.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.        try:            with open(audio_file_path, 'rb') as audio_file:                while True:                    chunk = audio_file.read(4096)                    print(chunk)                    if not chunk:                        break        except:                traceback.print_exc()                # The later requests contains audio data.
查看完整描述

2 回答

?
拉風(fēng)的咖菲貓

TA貢獻1995條經(jīng)驗 獲得超2個贊

所以顯然你正在傳遞StringIO到detect_intent_stream:audio_file_path


with open(audio_file_path, 'rb') as audio_file:

您嘗試將其StringIO作為文件打開


但:


StringIO 實例已經(jīng)是一個打開的文件。另一方面,open 命令只接受文件名來返回一個打開的文件。StringIO 實例不適合作為文件名。關(guān)聯(lián)


所以request_generator函數(shù)detect_intent_stream需要看起來像:


def request_generator(audio_config, audio_file_path):

        query_input = dialogflow.types.QueryInput(audio_config=audio_config)        

        yield dialogflow.types.StreamingDetectIntentRequest(

            session=session_path, query_input=query_input)        

        while True:

            chunk = audio_file_path.read(4096)

            if not chunk:

                break

            yield dialogflow.types.StreamingDetectIntentRequest(

            input_audio=chunk)


查看完整回答
反對 回復(fù) 2022-06-22
?
精慕HU

TA貢獻1845條經(jīng)驗 獲得超8個贊

您好,您的音頻文件或網(wǎng)絡(luò)連接可能有問題。您是否嘗試過發(fā)送一個簡單的文本或預(yù)先錄制的 wav 文件作為 dialogflow 的輸入?


這個腳本在我的辣椒上效果很好:(我的 wav 文件是 Mono,44100Hz,32Bit)


import os

import time

import sys

import uuid

import google


def printResponse(response):

    print('=' * 20)

    print('Query text: {}'.format(response.query_result.query_text.encode('utf-8')))

    print('Detected intent: {} (confidence: {})'.format(

        response.query_result.intent.display_name.encode('utf-8'),

        response.query_result.intent_detection_confidence))

    print('Fulfillment text: {}'.format(

        response.query_result.fulfillment_text.encode('utf-8')))



def detect_intent_audio(project_id, session_id, audio_file_path,

                        language_code, sample_rate_hertz):


    import dialogflow_v2 as dialogflow


    session_client = dialogflow.SessionsClient()


    # Note: hard coding audio_encoding and sample_rate_hertz for simplicity.

    audio_encoding = dialogflow.enums.AudioEncoding.AUDIO_ENCODING_LINEAR_16


    session = session_client.session_path(project_id, session_id)


    with open(audio_file_path, 'rb') as audio_file:

        input_audio = audio_file.read()


    audio_config = dialogflow.types.InputAudioConfig(

        audio_encoding=audio_encoding, language_code=language_code,

        sample_rate_hertz=sample_rate_hertz)

    query_input = dialogflow.types.QueryInput(audio_config=audio_config)


    response = session_client.detect_intent(

        session=session, query_input=query_input,

        input_audio=input_audio)


    printResponse(response)


def detect_intent_stream(project_id, session_id, audio_file_path,

                         language_code, sample_rate_hertz):


    import dialogflow_v2 as dialogflow

    session_client = dialogflow.SessionsClient()


    # Note: hard coding audio_encoding and sample_rate_hertz for simplicity.

    audio_encoding = dialogflow.enums.AudioEncoding.AUDIO_ENCODING_LINEAR_16


    session_path = session_client.session_path(project_id, session_id)


    def request_generator(audio_config, audio_file_path):

        query_input = dialogflow.types.QueryInput(audio_config=audio_config)


        # The first request contains the configuration.

        yield dialogflow.types.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.types.StreamingDetectIntentRequest(

                    input_audio=chunk)


    audio_config = dialogflow.types.InputAudioConfig(

        audio_encoding=audio_encoding, language_code=language_code,

        sample_rate_hertz=sample_rate_hertz)


    requests = request_generator(audio_config, audio_file_path)

    responses = session_client.streaming_detect_intent(requests)


    print('=' * 20)

    for response in responses:

        print('Intermediate transcript: "{}".'.format(

                response.recognition_result.transcript.encode('utf-8')))


    # Note: The result from the last response is the final transcript along

    # with the detected content.


    printResponse(response)


def detect_intent_texts(project_id, session_id, texts, language_code):


    import dialogflow_v2 as dialogflow

    session_client = dialogflow.SessionsClient()


    session = session_client.session_path(project_id, session_id)


    for text in texts:

        text_input = dialogflow.types.TextInput(

            text=text, language_code=language_code)


        query_input = dialogflow.types.QueryInput(text=text_input)


        response = session_client.detect_intent(

            session=session, query_input=query_input)


        printResponse(response)



project_id = 'my_project_id'

session_id = str(uuid.uuid4())

language_code = 'de'

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = os.path.join('/home/me/', 'xyz.json')

wav_path = os.path.join('/home/me/', 'audio.wav')


try:

    print ("detect_intent_texts:")

    detect_intent_texts(project_id, session_id, ["Hallo"], language_code)

    print('=' * 20)   


    print ("detect_intent_audio:")

    detect_intent_audio(project_id, session_id, wav_path, language_code, 44100)

    print('=' * 20)


    print ("detect_intent_stream:")

    detect_intent_stream(project_id, session_id, wav_path, language_code, 44100)

    print('=' * 20)

except google.api_core.exceptions.ServiceUnavailable:

        print("503 Connect Failed")


查看完整回答
反對 回復(fù) 2022-06-22
  • 2 回答
  • 0 關(guān)注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號