Installation
Add carp_audio_package to a CAMS app and configure Android and iOS.
Add the package, give the app microphone access on Android and iOS, raise the iOS deployment target, and register the package:
Add the packages
The package runs on top of CARP Mobile Sensing (CAMS), so complete the CAMS setup in Installation first. The steps below add only what the audio measures need.
Configure Android
Add the microphone permission to
android/app/src/main/AndroidManifest.xml, above the<application>element:android/app/src/main/AndroidManifest.xml NOISEandAUDIOboth need it: CAMS asks the participant forPermission.microphone, which isRECORD_AUDIOon Android. The package does not use the camera, so declareCAMERAonly if your app captures images or videos itself.The package needs
minSdk24 or later, becauseflutter_soundandaudio_streamerdo. Ifandroid/app/build.gradle.ktssets a lower value, raise it to 24.Configure iOS
audio_streamerrequires iOS 16.0 or later, which is higher than the CAMS minimum. In Xcode, select Runner → General and set Minimum Deployments to 16.0. Ifios/Podfilehas aplatformline, set it to the same version:ios/Podfile Add the microphone usage description and the
audiobackground mode toios/Runner/Info.plist. If the file already hasUIBackgroundModes, addaudioto its array:ios/Runner/Info.plist Noise sampling and recordings need the
audiobackground mode to continue when the app moves to the background. AddNSCameraUsageDescriptiononly if your app captures images or videos itself.AUDIOchecks the microphone permission throughpermission_handlerand records nothing until the check passes. How you enable microphone access inpermission_handlerdepends on how Flutter builds the iOS plugins:Swift Package Manager CocoaPods No change is needed:
permission_handler_appleenables microphone access when it findsNSMicrophoneUsageDescriptioninInfo.plist.flutter_soundis available through CocoaPods only, so CocoaPods must stay installed for the iOS build.Enable microphone access in the
post_installblock of the Podfile. If the block already setsGCC_PREPROCESSOR_DEFINITIONS, add the macro to that list:ios/Podfile Register the sampling package
Register the package in
main(), before you configure the client:Call
CarpMobileSensing.ensureInitialized()beforeregister(): registering a sampling package before CAMS is initialized throws a null check error.Registering the package makes its four measure types known to CAMS and registers the JSON types of their data.
configure()restores the studies saved on the phone and resumes their sampling, which needs the package's measure types.
Troubleshooting
Enable microphone access in permission_handler: add NSMicrophoneUsageDescription to Info.plist with Swift Package Manager, or the PERMISSION_MICROPHONE=1 macro to the Podfile with CocoaPods. AUDIO records nothing while permission_handler reports the microphone permission as denied.
Set Minimum Deployments to 16.0 in Xcode and platform :ios, '16.0' in the Podfile, then run pod install in the ios/ folder again. audio_streamer 5.0.0 does not build for earlier iOS versions.
Next step
Quickstart
Build an app that samples noise and records audio.