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


Java AudioOutConfig類代碼示例

本文整理匯總了Java中com.google.assistant.embedded.v1alpha1.AudioOutConfig的典型用法代碼示例。如果您正苦於以下問題:Java AudioOutConfig類的具體用法?Java AudioOutConfig怎麽用?Java AudioOutConfig使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AudioOutConfig類屬於com.google.assistant.embedded.v1alpha1包,在下文中一共展示了AudioOutConfig類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import com.google.assistant.embedded.v1alpha1.AudioOutConfig; //導入依賴的package包/類
@Override
public void run() {
    Log.i(TAG, "starting assistant request");
    mAudioRecord.startRecording();
    mAssistantRequestObserver = mAssistantService.converse(mAssistantResponseObserver);
    ConverseConfig.Builder converseConfigBuilder = ConverseConfig.newBuilder()
            .setAudioInConfig(AudioInConfig.newBuilder()
                    .setEncoding(ENCODING_INPUT)
                    .setSampleRateHertz(SAMPLE_RATE)
                    .build())
            .setAudioOutConfig(AudioOutConfig.newBuilder()
                    .setEncoding(ENCODING_OUTPUT)
                    .setSampleRateHertz(SAMPLE_RATE)
                    .setVolumePercentage(mVolumePercentage)
                    .build());
    if (mConversationState != null) {
        converseConfigBuilder.setConverseState(ConverseState.newBuilder()
                .setConversationState(mConversationState)
                .build());
    }
    mAssistantRequestObserver.onNext(
        ConverseRequest.newBuilder()
            .setConfig(converseConfigBuilder.build())
            .build());
    mAssistantHandler.post(mStreamAssistantRequest);
}
 
開發者ID:googlecodelabs,項目名稱:androidthings-googleassistant,代碼行數:27,代碼來源:AssistantActivity.java

示例2: startRecognizing

import com.google.assistant.embedded.v1alpha1.AudioOutConfig; //導入依賴的package包/類
public void startRecognizing(int sampleRate) {

        if (mApi == null) {
            Log.w(TAG, "API not ready. Ignoring the request.");
            return;
        }
        //Log.d(TAG,"request sending");
        for (Listener listener : mListeners) {
            listener.onRequestStart();
           // Log.d(TAG,"request sending");
        }
        // Configure the API
        mRequestObserver = mApi.converse(mResponseObserver);
        ConverseConfig.Builder converseConfigBuilder =ConverseConfig.newBuilder()
                .setAudioInConfig(AudioInConfig.newBuilder()
                        .setEncoding(AudioInConfig.Encoding.LINEAR16)
                        .setSampleRateHertz(sampleRate)
                        .build())
                .setAudioOutConfig(AudioOutConfig.newBuilder()
                        .setEncoding(AudioOutConfig.Encoding.LINEAR16)
                        .setSampleRateHertz(sampleRate)
                        .setVolumePercentage(DEFAULT_VOLUME)
                        .build());
        if (vConversationState != null) {
            converseConfigBuilder.setConverseState(
                    ConverseState.newBuilder()
                            .setConversationState(vConversationState)
                            .build());
        }
        mRequestObserver.onNext(ConverseRequest.newBuilder()
                .setConfig(converseConfigBuilder.build())
                .build());



    }
 
開發者ID:hsavaliya,項目名稱:GoogleAssistantSDK,代碼行數:37,代碼來源:SpeechService.java

示例3: build

import com.google.assistant.embedded.v1alpha1.AudioOutConfig; //導入依賴的package包/類
/**
 * Returns an AssistantManager if all required parameters have been supplied.
 *
 * @return An inactive AssistantManager. Call {@link EmbeddedAssistant#connect()} to start
 * it.
 */
public EmbeddedAssistant build() {
    if (mEmbeddedAssistant.mRequestCallback == null) {
        throw new NullPointerException("There must be a defined RequestCallback");
    }
    if (mEmbeddedAssistant.mConversationCallback == null) {
        throw new NullPointerException("There must be a defined ConversationCallback");
    }
    if (mEmbeddedAssistant.mUserCredentials == null) {
        throw new NullPointerException("There must be provided credentials");
    }
    if (mSampleRate == 0) {
        throw new NullPointerException("There must be a defined sample rate");
    }
    final int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;

    // Construct audio configurations.
    mEmbeddedAssistant.mAudioInConfig = AudioInConfig.newBuilder()
            .setEncoding(AudioInConfig.Encoding.LINEAR16)
            .setSampleRateHertz(mSampleRate)
            .build();
    mEmbeddedAssistant.mAudioOutConfig = AudioOutConfig.newBuilder()
            .setEncoding(AudioOutConfig.Encoding.LINEAR16)
            .setSampleRateHertz(mSampleRate)
            .setVolumePercentage(mEmbeddedAssistant.mVolume)
            .build();

    // Initialize Audio framework parameters.
    mEmbeddedAssistant.mAudioInputFormat = new AudioFormat.Builder()
            .setChannelMask(AudioFormat.CHANNEL_IN_MONO)
            .setEncoding(audioEncoding)
            .setSampleRate(mSampleRate)
            .build();
    mEmbeddedAssistant.mAudioInputBufferSize = AudioRecord.getMinBufferSize(
            mEmbeddedAssistant.mAudioInputFormat.getSampleRate(),
            mEmbeddedAssistant.mAudioInputFormat.getChannelMask(),
            mEmbeddedAssistant.mAudioInputFormat.getEncoding());
    mEmbeddedAssistant.mAudioOutputFormat = new AudioFormat.Builder()
            .setChannelMask(AudioFormat.CHANNEL_OUT_MONO)
            .setEncoding(audioEncoding)
            .setSampleRate(mSampleRate)
            .build();
    mEmbeddedAssistant.mAudioOutputBufferSize = AudioTrack.getMinBufferSize(
            mEmbeddedAssistant.mAudioOutputFormat.getSampleRate(),
            mEmbeddedAssistant.mAudioOutputFormat.getChannelMask(),
            mEmbeddedAssistant.mAudioOutputFormat.getEncoding());


    // create new AudioRecord to workaround audio routing issues.
    mEmbeddedAssistant.mAudioRecord = new AudioRecord.Builder()
            .setAudioSource(AudioSource.VOICE_RECOGNITION)
            .setAudioFormat(mEmbeddedAssistant.mAudioInputFormat)
            .setBufferSizeInBytes(mEmbeddedAssistant.mAudioInputBufferSize)
            .build();
    if (mEmbeddedAssistant.mAudioInputDevice != null) {
        boolean result = mEmbeddedAssistant.mAudioRecord.setPreferredDevice(
                mEmbeddedAssistant.mAudioInputDevice);
        if (!result) {
            Log.e(TAG, "failed to set preferred input device");
        }
    }

    return mEmbeddedAssistant;
}
 
開發者ID:androidthings,項目名稱:sample-googleassistant,代碼行數:70,代碼來源:EmbeddedAssistant.java


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