CARP Media Sampling Package
The name of the Flutter pub.dev package is "audio" for historical reasons - however, it is (now) a "media" package and the CAMS package name is
For Flutter plugins for other CARP products, see CARP Mobile Sensing in Flutter.
If you're interested in writing you own sampling packages for CARP, see the description on how to extend CARP on the wiki.
To use this package, add the following to you
pubspc.yaml file. Note that
this package only works together with
dependencies: flutter: sdk: flutter carp_core: ^latest carp_mobile_sensing: ^latest carp_audio_package: ^latest ...
Add the following to your app's
AndroidManifest.xml file located in
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Add this permission in the
Info.plist file located in
<key>NSMicrophoneUsageDescription</key> <string>Uses the microphone to record ambient noise in the phone's environment.</string> <key>NSCameraUsageDescription</key> <string>Uses the camera to ....</string> <key>UIBackgroundModes</key> <array> <string>audio</string> <string>external-accessory</string> <string>fetch</string> </array>
To use this package, import it into your app together with the
import 'package:carp_core/carp_core.dart'; import 'package:carp_mobile_sensing/carp_mobile_sensing.dart'; import 'package:carp_audio_package/media.dart';
Before creating a study and running it, register this package in the SamplingPackageRegistry.
Adding audio measure from this package to a study protocol would look something like:
// Create a study protocol StudyProtocol protocol = StudyProtocol( ownerId: 'firstname.lastname@example.org', name: 'Audio Sensing Example', ); // Define which devices are used for data collection // In this case, its only this smartphone Smartphone phone = Smartphone(); protocol.addPrimaryDevice(phone); // Add an automatic task that immediately starts collecting audio and noise. protocol.addTaskControl( ImmediateTrigger(), BackgroundTask(measures: [ Measure(type: MediaSamplingPackage.AUDIO), Measure(type: MediaSamplingPackage.NOISE), ]), phone);
- A library for collecting an audio recording from the phone's microphone. Support the following measures: