fulldecent /FDSoundActivatedRecorder

Start recording when the user speaks

★ 299⑂ 65👁 14⑃ 12● 28▤ 15◈ 0
SwiftMITCreated 2013-12-23
299
stars
65
forks
14
watchers
12
prs
28
issues
15
releases
0
discussions

README

FDSoundActivatedRecorder

 

plain
  V
  O                 /-----------\
  L                /             \
  U          Rise /               \ Fall
  M              /                 \
  E  -----------/                   \-----------
 
        Quiet   |   Recorded file   |   Quiet


 Example

Clone the repo and open Example/Example.xcodeproj. Run the Example scheme on a recent iPhone simulator.

 Installation

Add this package with Swift Package Manager. In Xcode that is File  Add Package Dependencies...

 Development

Run the package tests on an iPhone simulator. Package.swift requires iOS 16 and the library records through AVFoundation, so the destination is a simulator. This is the same command .github/workflows/ci.yml runs, with the simulator chosen from the ones installed on this Mac:

sh
UDID=$(xcrun simctl list devices available | awk -F '[()]' '/iPhone/ { print $2; exit }')
xcodebuild -scheme FDSoundActivatedRecorder -destination "id=$UDID" test


 Maintenance and dependency updates

Do this every quarter, and send a pull request when an update is safe. The list is the one in swift-module-template, applied to the files this repository actually has:

1. Review the external Actions in .github/workflows/ci.yml and the xcode-27 runner image. GitHub-supported Actions (the actions/ organization) need a short review.
2. Re-read swift-module-template at the release in References. When a newer release is published, adopt it and update that citation in the same change.

 License

FDSoundActivatedRecorder is available under the MIT license. See the LICENSE file for more information.

 Features

- You can start recording when sound is detected
- Sound stops recording when the user is done talking
- Works with ARC and iOS 16+

 Usage

Import the project with:

swift
import FDSoundActivatedRecorder


Then begin listening with:

swift
self.recorder = FDSoundActivatedRecorder()
self.recorder.delegate = self
self.recorder.startListening()


A full implementation example is provided in this project.

 Regular recorder

If you want to use it as a regular recorder, without trimming the audio, you can tweak the Configuration to achieve that.

 Full API

The full API, from
FDSoundActivatedRecorder.swift
is copied below:

// FIXME: PASTE HERE

 Technical discussion

This library is tuned for human speech detection using Apple retail iOS devices
in a quiet or noisy environement. You are welcome to tune the audio detection
constants of this program for any special needs you may have. Following is a
technical description of how the algorithm works from
FDSoundActivatedRecorder.swift.

plain
  V
  O                 /-----------\
  L                /             \
  U          Rise /               \ Fall
  M              /                 \
  E  -----------/                   \-----------
 
        Quiet   |   Recorded file   |   Quiet


- We listen and save audio levels every INTERVAL
- When several levels exceed the recent moving average by a threshold, we record

Latest release

Swift concurrency 4.0.0 2025-07-25
Changed

- Implemented Swift 6 and thread safety
- Moved configuration API to a separate struct and you can specify it once at initialization
- fixed rise intervals count constant used for recording activation by @shalamowww in https://github.com/fulldecent/FDSoundActivatedRecorder/pull/37

 Removed

- Removed state change functions except for startListening(), abort(). The others were mostly for debugging.

 Fixes

- Crashes because dyld library not loaded, issue 24

 New contributors
 @shalamowww made their first contribution in https://github.com/fulldecent/FDSoundActivatedRe

Snapshot: 2026-11-11T15:31:17Z · Data license Apache-2.0 · JSON