Overview

1. spaceGearSDK AAR

Copy the spaceGearSDK-debug.aar library file to agentSample/app/aar.

app/build.gradle

Set implementation AAR.


dependencies {
    .
    .
    .
    implementation files('aar/spaceGearSDK-debug.aar')
}

2. Init VoiceAgent

MainActivity.java

VoiceAgent.getInstance().init(this, "SPACEGEAR_VOICEAGENT_ACCESS_KEY");

3. Run VoiceAgent

  • Set Setting Parameter

VoiceAgent.getInstance().setSettingParameter(
    VASettingParameter.AGENT_TYPE,
    "spacegear"
);
  • Start Voice Recording

// Voice recording will be automatically started.
VoiceAgent.getInstance().startRecording();
  • End Voice Recording

// Voice recording will be stopped and audio file path returned.
String audioFilePath = VoiceAgent.getInstance().finishRecording(); 
  • Send Audio Data

// Send audio data via WebSocket.
VoiceAgent.getInstance().sendAudioViaWebSocket(audioFilePath);
  • Cancel Voice Recording

// Current recording session stopped and do nothing.
VoiceAgent.getInstance().cancelRecording();
  • Stop Audio Stream Player

// When audio stream chunk received, audio stream will be automatically played.
// You can stop the audio player like this way.
VoiceAgent.getInstance().stopAudioPlaying();
  • Get Current State

// You can check the states of AudioPlayer, Recorder, NetworkManager.
boolean isWebSocketConnected = VoiceAgent.getInstance().isWebSocketConnected();
boolean isRecording = VoiceAgent.getInstance().isRecording();
boolean isAudioPlaying= VoiceAgent.getInstance().isAudioPlaying();

4. Set EventListener

// You can add your custom event listener via this method. 
// Check the supported event types.
VoiceAgent.getInstance().setEventListener(
    VAEvent.ON_INPUT_TRANSCRIPTION, (data) -> { // JSON data used.
        Toast.makeText(
            context,
            data.getString("input"),
            Toast.LENGTH_LONG
        );
    }
);
  • Supported Event Type

    • ON_RECORD_START

    • ON_RECORD_DONE

    • ON_WEBSOCKET_OPEN

    • ON_WEBSOCKET_TEXT_MESSAGE

    • ON_WEBSOCKET_BINARY_DATA

    • ON_WEBSOCKET_CLOSING

    • ON_WEBSOCKET_FAILURE

    • ON_INPUT_TRANSCRIPTION

    • ON_OUTPUT_AGENT_TEXT_CHUNK

    • ON_OUTPUT_AGENT_AUDIO_CHUNK

    • ON_AUDIO_DATA_SEND

    • ON_RESPONSE_DONE

Last updated