STYLY for Vision Pro: How to record and playback with a microphone ,Easy implementation with Unity Visual Scripting

This time, we will introduce how to record and play back audio within STYLY for Vision Pro.

Place the Microphone

1. Place a Cube in the Hierarchy for the microphone.

2. Add the following components to the Cube:

  • AudioSource (Add via Add Component)
  • ScriptMachine (Add via Add Component)
Image5

To enable the Visual Scripting nodes used in this tutorial, open Edit → Project Settings.

Image6

Open TypeOptions under the Visual Scripting tab.

Image2

Scroll to the bottom, press the + button, and add a new option.

Image14

Add Microphone.

Image8

Press Regenerate Nodes to rebuild the options.

Image7

Preparing for Recording

1. Create a new ScriptGraph in ScriptMachine.

  • Example: “Voice Recorder”

2. Add the following variable to ObjectVariable:

  • Name: AudioSource
  • Type: “AudioSource”
Image3

3. Assign the AudioSource from the Cube in the Hierarchy to the AudioSource variable by dragging and dropping.

Image1

4. Add the following components to the Cube:

  • XR Grab Interactable
  • XR Poke Filter
  • Add settings to the Interactable Filter in XR Grab Interactable’s Hover option.
    • For more details, refer to STYLY for Vision Pro: How to Easily Implement Button Operations with the Poke Feature.
Image4

Building the ScriptGraph

Add and connect the following nodes:

Access Vision Pro’s Microphone

  1. Use GetDevices and FirstItem nodes to get Vision Pro’s microphone.
  2. Assign the microphone name to the Device Name field in the Start node.
  3. Settings for the Start node:
    • Length Sec: Recording duration (e.g., 5 seconds)
    • Frequency: Sampling rate (e.g., 44100Hz)
Image15

Setting Recording Conditions

  1. Use GetPosition to get the volume level.
  2. Add a condition to skip recording if the volume is 0 or lower (i.e., no sound is detected).
Image10

Visual Feedback During Recording

  1. Create a new Material and attach it to the Cube.
  2. Use SetColor to indicate recording and playback states:
    • Recording: Red
    • Playback: Blue
Image12

Implementing Recording and Playback

Add and connect the following nodes:

  1. Use a Timer node to manage the recording time (5 seconds).
  2. Use an End node to stop recording.
  3. Use a Play node to play the recorded audio.
Image9

Node 1: xxxxx

Image11

Node 2: Full Graph

Run

You can now successfully record and play back audio.

Watch with audio here:

https://youtu.be/-TdT8xdYyP0