Interface AudioRecordingService

  • All Known Implementing Classes:
    DefaultAudioRecordingService, DesktopAudioRecordingService, DummyAudioRecordingService, IOSAudioRecordingService

    public interface AudioRecordingService
    AudioRecording Service.

    Service to record audio. The recording is saved in wav format in chunk files of a given duration. The files are stored in the public storage, under a folder that the developer will set. The pattern for these files name will be audioFile-###-yyyy-MM-dd.HH-mm-ss.SSS,wav, where ### is the number of chunk, starting from 000.

    Note that given the limited space available on the device, it is convenient to remove the content either before starting a new recording or when the files have been extracted.



    The following code snippet shows how to start recording 10 minutes of audio in 10 files of 1 minute duration each.

     AudioRecordingService.create().ifPresent(audio -> {
          audio.getAudioChunkFiles().addListener((ListChangeListener.Change<? extends String> c) -> {
              while ( {
                  if (c.wasAdded()) {
                      for (String fileName : c.getAddedSubList()) {
                          File audioFile = new File(audio.getAudioFolder(), fileName);
                          System.out.println("New audio chunk: " + audioFile.getAbsolutePath());
                  if (audio.getAudioChunkFiles().size() == 10) {
         audio.startRecording(44100f, 16, 2, 60);


    The service requires the following changes on Android and iOS.

    However, these are handled automatically by the GluonFX plugin, when used.

    Android Configuration

    The following permission and activity need to be added to the android manifest configuration file:

     <manifest ...>
        <uses-permission android:name="android.permission.RECORD_AUDIO" />
        <application ...>
           <activity android:name="" />

    iOS Configuration

    The following keys are required:

     <string>Need microphone access for recording audio</string>
    Note: to get access to the public storage from iTunes these keys can be added as well:
    • Field Detail


        static final java.lang.String DEFAULT_EXTERNAL_FOLDER
        See Also:
        Constant Field Values
    • Method Detail

      • setAudioFolderName

        void setAudioFolderName​(java.lang.String folderName)
        Sets the name of the external folder where the audio files will be saved. If not set, by default it will use DEFAULT_EXTERNAL_FOLDER.
        folderName - the name of the external folder where the audio files will be saved
      • getAudioFolder getAudioFolder()
        Returns the folder where all the audio files will be stored
        a File with the audio folder
      • clearAudioFolder

        void clearAudioFolder()
        Removes the content of the audio folder.

        This method can be called at any time. It is convenient to call it before the audio recording starts, or when it ends and the audio files have been safely extracted.

      • startRecording

        void startRecording​(float sampleRate,
                            int sampleSizeInBits,
                            int channels,
                            int chunkRecordTime)
        Start audio recording with the given parameters. The recorded audio files are saved in wav format in chunks of the specified recording time.
        sampleRate - the number of samples per second (8000.0f, 44100.0f, ...)
        sampleSizeInBits - the number of bits in each sample (16 or 8)
        channels - the number of channels (1 for mono, 2 for stereo)
        chunkRecordTime - the duration in seconds of each chunk (60, 360, ...)
      • stopRecording

        void stopRecording()
        Stop audio recording.
      • recordingProperty recordingProperty()
        Returns true when the audio recording is currently active and false if audio recording is stopped.
        a read only boolean property with the recording status
      • getAudioChunkFiles<java.lang.String> getAudioChunkFiles()
        Returns a read only observable list of file names. It contains a list of file chunks that are saved in the audio folder. It can be used during recording to track when new audio chunks are made available in the audio folder.
        A ReadOnlyListProperty of file names