- 结合音频处理和触觉反馈,提供实时的音频可感知化体验
- 支持自定义音频文件和频率范围
- 提供循环播放选项
- 实现了后台暂停和前台恢复功能
- 使用 Core Haptics 框架提供触觉反馈
- 利用 Accelerate 框架进行高效的 FFT 计算
- 需要 iOS 13.0 或更高版本,因为使用了 Core Haptics 框架
- 触觉反馈依赖于设备硬件支持,部分设备可能不支持
- 音频处理可能会增加设备的电池消耗
- 大文件或高采样率的音频可能会影响性能
.package(url: "https://github.com/excitedcosmos/ECWavingHaptics.git", from: "1.0.0")
或者
https://github.com/excitedcosmos/ECWavingHaptics.git
let haptics = ECWavingHaptics(
audioFileURL: URL(fileURLWithPath: "path/to/audio/file"),
audioFormat: AVAudioFormat(standardFormatWithSampleRate: 44100, channels: 2)!,
minFrequency: 20,
maxFrequency: 20000,
isLooping: true,
playCallback: { print("开始播放") },
stopCallback: { print("停止播放") },
errorCallback: { error in print("错误:\(error)") }
)
参数说明:
audioFileURL
: 音频文件的 URLaudioFormat
: 音频格式,包括采样率和通道数minFrequency
: 最小频率,单位为 HzmaxFrequency
: 最大频率,单位为 HzisLooping
: 是否循环播放playCallback
: 开始播放时的回调函数stopCallback
: 停止播放时的回调函数errorCallback
: 发生错误时的回调函数
haptics.startAudioProcessing()
haptics.stopAudioProcessing()
deinit {
haptics.stopAudioProcessing()
}
- Combines audio processing and haptic feedback to provide real-time audio sensorization experience
- Supports custom audio files and frequency ranges
- Offers looping playback option
- Implements background pause and foreground resume functionality
- Uses Core Haptics framework for haptic feedback
- Utilizes Accelerate framework for efficient FFT calculations
- Requires iOS 13.0 or higher due to the use of Core Haptics framework
- Haptic feedback depends on device hardware support, some devices may not support it
- Audio processing may increase device battery consumption
- Large files or high sample rate audio may affect performance
-
Create an
ECWavingHaptics
instance:let haptics = ECWavingHaptics( audioFileURL: URL(fileURLWithPath: "path/to/audio/file"), audioFormat: AVAudioFormat(standardFormatWithSampleRate: 44100, channels: 2)!, minFrequency: 20, maxFrequency: 20000, isLooping: true, playCallback: { print("Playback started") }, stopCallback: { print("Playback stopped") }, errorCallback: { error in print("Error: \(error)") } )
Parameter description:
audioFileURL
: URL of the audio fileaudioFormat
: Audio format, including sample rate and number of channelsminFrequency
: Minimum frequency in HzmaxFrequency
: Maximum frequency in HzisLooping
: Whether to loop playbackplayCallback
: Callback function when playback startsstopCallback
: Callback function when playback stopserrorCallback
: Callback function when an error occurs
-
Start audio processing and haptic feedback:
haptics.startAudioProcessing()
-
Stop audio processing and haptic feedback:
haptics.stopAudioProcessing()
-
Release resources at the appropriate time:
deinit { haptics.stopAudioProcessing() }