Skip to content
CARP Docs
Ask AISystemLightDark
On this page

Audio Sampling Package

Collect noise levels and audio recordings from the phone's microphone in a CARP Mobile Sensing study.

Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor

carp_audio_package adds the phone's microphone to a CARP Mobile Sensing (CAMS) study. It measures the noise level around the participant and records audio to files, for example to study the sound environment or a participant's cough. It also defines data types for videos and images that your app captures.

The package is named after audio for historical reasons, but it is a media package. Its classes are named for media, such as MediaSamplingPackage, and its library is package:carp_audio_package/media.dart. Noise levels come from the noise_meter plugin and recordings from flutter_sound.

pub.devAPI referenceGitHub

Recording people

AUDIO records everything the microphone picks up, including the voices of people nearby who have not agreed to take part, and stores it unchanged. The study's ethics approval and consent must cover audio recordings. When sound levels are enough, use NOISE, which stores no sound.

Features

Noise

The mean, standard deviation, minimum and maximum sound level in decibels for a short window every few minutes. No sound is stored.

Audio recordings

Recordings from the microphone, stored as AAC files on the phone and started and stopped by the study protocol or by the participant.

Video and images

Data types for videos and images that your app captures, so that they are stored and uploaded with the study data. The package does not use the camera.

Measure types

Measure typeDataAndroidiOS
dk.cachet.carp.noiseSound level statistics in decibels for each sampling windowYesYes
dk.cachet.carp.audioAn audio recording, stored as a fileYesYes
dk.cachet.carp.videoA video that your app recordsYesYes
dk.cachet.carp.imageAn image that your app capturesYesYes

NOISE is event-based, AUDIO records from when its task starts until the task stops, and VIDEO and IMAGE collect nothing by themselves. For the kinds of measures, see Event-based and one-time measures.

Requirements

ComponentRequirement
Dart SDK3.10 or later
Flutter3.44 or later, required by noise_meter
carp_mobile_sensing2.2.0 or later
AndroidAPI level 24 (Android 7.0) or later
iOS16.0 or later, required by audio_streamer, which noise_meter uses

How it works

Adding the package to a study takes three steps:

  1. Register the package

    Registering MediaSamplingPackage makes the four measure types and their data classes known to CAMS.

  2. Add the measures to a protocol

    NOISE starts with an ImmediateTrigger() and schedules its own sampling windows. Each AUDIO recording needs a task that stops, for example after a fixed duration.

  3. Deploy the protocol

    CAMS asks the participant for microphone access, samples noise in short windows and adds an audio measurement each time a recording stops.

This example registers the package and samples the noise level for 10 seconds every 5 minutes, the default:

import 'package:carp_core/carp_core.dart' hide Smartphone;
import 'package:carp_mobile_sensing/carp_mobile_sensing.dart';
import 'package:carp_audio_package/media.dart';

void main() {
  CarpMobileSensing.ensureInitialized();
  SamplingPackageRegistry().register(MediaSamplingPackage());

  final protocol = SmartphoneStudyProtocol(
    ownerId: 'owner@example.com',
    name: 'Ambient noise',
    dataEndPoint: SQLiteDataEndPoint(),
  );
  final phone = Smartphone();
  protocol.addPrimaryDevice(phone);

  // An event-based measure starts once and runs until the study pauses
  protocol.addTaskControl(
    ImmediateTrigger(),
    BackgroundTask(measures: [Measure(type: MediaSamplingPackage.NOISE)]),
    phone,
  );

  // ... deploy the protocol and start sampling
}

Next steps

Installation

Add the package to a CAMS app and configure Android and iOS.

Quickstart

Build an app that samples noise and records audio.

Noise

Sampling windows, decibel values and the noise data.

Audio recordings

Start and stop recordings, and find and upload the files.

Quick links

Page · DocumentationCARP DocumentationPage · DocumentationIntroductionPage · DocumentationQuickstartPage · DocumentationTerminologyPage · DocumentationArchitecture