Skip to main content

Microphone

Description

The Microphone app provides a practical example of how to access the Quest's microphone and handle Android permissions. It processes live microphone samples in real-time and converts them into an audio spectrum.

Image: Screenshot Finger Distance app

The app utilizes the PlatformSDK to access the Quest's microphone. Once the microphone is activated, the onMicrophoneSample() event function receives real-time audio samples. These samples are then transformed into individual frequencies using a Fast Fourier Transform and stored in a member variable of the application.

Before each frame is rendered, the updateMicrophoneSpectrum() function is executed. Whenever new audio frequencies are received, they are visualized using a line strip. Additionally, a per-vertex color is applied to create a visually engaging effect.

Before the microphone can be activated, the app must obtain permission from the user. Therefore, the record audio permission (android.permission.RECORD_AUDIO) is included in the app's manifest file and is additionally requested when the application starts. Once the user grants permission, the onAndroidPermissionGranted() function is invoked, allowing the microphone to be accessed.

Building

The following instructions are for macOS but can be easily converted to other host operating systems. First, ensure that the

have been completed. And that the third-party libraries have been built according to these instructions.

Then run the following steps:

# Define environment variables required for Android and Quest apps as per setup instructions above:
# ANDROID_HOME, ANDROID_NDK, ANDROID_NDK_VERSION, JAVA_HOME, and OVRPlatformSDK_ROOT

# Adjust this to your location of the third-party libraries
export OCEAN_THIRDPARTY_PATH="${HOME}/install_ocean_thirdparty"

cd ${OCEAN_DEVELOPMENT_PATH}/build/gradle/application/ocean/demo/platform/meta/quest/openxr/microphone/quest

./gradlew assemble

# Install debug build of the app
adb install app/build/outputs/apk/debug/app-debug.apk

# Install release build of the app
adb install app/build/outputs/apk/release/app-release.apk

Features

  • Microphone Access: Demonstrates how to access the Quest's microphone for audio input.
  • Android Permission Handling: Shows how to request and handle Android permissions required for microphone access.
  • Real-Time Audio Processing: Processes live microphone samples and converts them into an audio spectrum display.

Application Integration

  • Audio-Based Interactions: Enables developers to integrate audio-based interactions or features into their VR applications.