├── .gitignore ├── .swift-version ├── AudioBot.podspec ├── AudioBot ├── AudioBot.h ├── AudioBot.swift ├── FileManager+AudioBot.swift └── Info.plist ├── LICENSE ├── README.md ├── VoiceMemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ └── AudioBot.xcscheme └── VoiceMemo ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── Contents.json ├── icon_pause.imageset │ ├── Contents.json │ └── icon_pause.pdf └── icon_play.imageset │ ├── Contents.json │ └── icon_play.pdf ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── FileManager+VoiceMemo.swift ├── Info.plist ├── RecordButton.swift ├── ViewController.swift ├── VoiceMemo.swift ├── VoiceMemoCell.swift └── Waver.swift /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ## Build generated 3 | build/ 4 | DerivedData 5 | 6 | ## Various settings 7 | *.pbxuser 8 | !default.pbxuser 9 | *.mode1v3 10 | !default.mode1v3 11 | *.mode2v3 12 | !default.mode2v3 13 | *.perspectivev3 14 | !default.perspectivev3 15 | xcuserdata 16 | 17 | ## Other 18 | *.xccheckout 19 | *.moved-aside 20 | *.xcuserstate 21 | *.xcscmblueprint 22 | 23 | ## Obj-C/Swift specific 24 | *.hmap 25 | *.ipa 26 | 27 | # CocoaPods 28 | Pods/ 29 | 30 | # Carthage 31 | Carthage/Checkouts 32 | Carthage/Build 33 | 34 | 35 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 2 | -------------------------------------------------------------------------------- /AudioBot.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "AudioBot" 4 | s.version = "1.2.2" 5 | s.summary = "AudioBot helps your do audio record & playback." 6 | 7 | s.description = <<-DESC 8 | AudioBot make audio record & playback easier. 9 | It will do decibel sampling when recording. 10 | And it can mix playing music when recording. 11 | DESC 12 | 13 | s.homepage = "https://github.com/nixzhu/AudioBot" 14 | 15 | s.license = { :type => "MIT", :file => "LICENSE" } 16 | 17 | s.authors = { "nixzhu" => "zhuhongxu@gmail.com" } 18 | s.social_media_url = "https://twitter.com/nixzhu" 19 | 20 | s.ios.deployment_target = "8.0" 21 | 22 | s.source = { :git => "https://github.com/nixzhu/AudioBot.git", :tag => s.version } 23 | s.source_files = "AudioBot/*.swift" 24 | s.requires_arc = true 25 | 26 | end 27 | -------------------------------------------------------------------------------- /AudioBot/AudioBot.h: -------------------------------------------------------------------------------- 1 | // 2 | // AudioBot.h 3 | // AudioBot 4 | // 5 | // Created by NIX on 15/11/28. 6 | // Copyright © 2015年 nixWork. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for AudioBot. 12 | FOUNDATION_EXPORT double AudioBotVersionNumber; 13 | 14 | //! Project version string for AudioBot. 15 | FOUNDATION_EXPORT const unsigned char AudioBotVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /AudioBot/AudioBot.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AudioBot.swift 3 | // AudioBot 4 | // 5 | // Created by NIX on 15/11/28. 6 | // Copyright © 2015年 nixWork. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import AVFoundation 11 | 12 | public enum AudioBotError: Error { 13 | case invalidReportingFrequency 14 | case noFileURL 15 | } 16 | 17 | public final class VADSettings: NSObject { 18 | public var longestDuration: TimeInterval = 30.0 19 | public var spaceDuration: TimeInterval = 2.0 20 | public var silenceDuration: TimeInterval = 0.5 21 | public var silenceVolume: Float = 0.1 22 | } 23 | 24 | final public class AudioBot: NSObject { 25 | 26 | fileprivate static let sharedBot = AudioBot() 27 | 28 | private override init() { 29 | super.init() 30 | } 31 | 32 | fileprivate lazy var normalAudioRecorder: AVAudioRecorder = { 33 | let fileURL = FileManager.audiobot_audioFileURLWithName(UUID().uuidString, Usage.normal.type)! 34 | return try! AVAudioRecorder(url: fileURL, settings: Usage.normal.settings) 35 | }() 36 | 37 | fileprivate var audioRecorder: AVAudioRecorder? 38 | fileprivate var audioPlayer: AVAudioPlayer? 39 | 40 | public static var isRecording: Bool { 41 | return sharedBot.audioRecorder?.isRecording ?? false 42 | } 43 | 44 | public static var recordingFileURL: URL? { 45 | return sharedBot.audioRecorder?.url 46 | } 47 | 48 | public static var isPlaying: Bool { 49 | return sharedBot.audioPlayer?.isPlaying ?? false 50 | } 51 | 52 | public static var playingFileURL: URL? { 53 | return sharedBot.audioPlayer?.url 54 | } 55 | 56 | public static var reportRecordingDuration: ((_ duration: TimeInterval) -> Void)? 57 | public static var reportPlayingDuration: ((_ duration: TimeInterval) -> Void)? 58 | 59 | fileprivate var recordingTimer: Timer? 60 | fileprivate var playingTimer: Timer? 61 | 62 | fileprivate var automaticRecordEnable = false 63 | 64 | public typealias PeriodicReport = (reportingFrequency: TimeInterval, report: (_ value: Float) -> Void) 65 | public typealias ResultReport = ((_ fileURL: URL, _ duration: TimeInterval, _ decibelSamples: [Float]) -> Void) 66 | 67 | fileprivate var recordingPeriodicReport: PeriodicReport? 68 | fileprivate var playingPeriodicReport: PeriodicReport? 69 | 70 | fileprivate var playingFinish: ((Bool) -> Void)? 71 | 72 | fileprivate var decibelSamples: [Float] = [] 73 | 74 | fileprivate func clearForRecording() { 75 | AudioBot.reportRecordingDuration = nil 76 | recordingTimer?.invalidate() 77 | recordingTimer = nil 78 | recordingPeriodicReport = nil 79 | decibelSamples = [] 80 | } 81 | 82 | fileprivate func clearForPlaying(finish: Bool) { 83 | AudioBot.reportPlayingDuration = nil 84 | playingTimer?.invalidate() 85 | playingTimer = nil 86 | if finish { 87 | playingPeriodicReport?.report(0) 88 | } 89 | playingPeriodicReport = nil 90 | } 91 | 92 | fileprivate func deactiveAudioSessionAndNotifyOthers() { 93 | if automaticRecordEnable { return } 94 | _ = try? AVAudioSession.sharedInstance().setActive(false, with: .notifyOthersOnDeactivation) 95 | } 96 | } 97 | 98 | // MARK: - Record 99 | 100 | extension AudioBot { 101 | 102 | public class func prepareForNormalRecord() { 103 | DispatchQueue.global(qos: .utility).async { 104 | sharedBot.normalAudioRecorder.prepareToRecord() 105 | } 106 | } 107 | 108 | public enum Usage { 109 | case normal 110 | case custom(fileURL: URL?, type: String, settings: [String: Any]) 111 | 112 | public static let m4aSettings: [String: Any] = [ 113 | AVFormatIDKey: Int(kAudioFormatMPEG4AAC), 114 | AVEncoderAudioQualityKey: AVAudioQuality.medium.rawValue, 115 | AVEncoderBitRateKey: 64000, 116 | AVNumberOfChannelsKey: 2, 117 | AVSampleRateKey: 44100.0 118 | ] 119 | 120 | public static let wavSettings: [String: Any] = [ 121 | AVFormatIDKey: Int(kAudioFormatLinearPCM), 122 | AVEncoderAudioQualityKey : AVAudioQuality.medium.rawValue, 123 | AVEncoderBitRateKey : 64000, 124 | AVNumberOfChannelsKey: 2, 125 | AVSampleRateKey : 44100.0 126 | ] 127 | 128 | var settings: [String: Any] { 129 | switch self { 130 | case .normal: 131 | return Usage.m4aSettings 132 | case .custom(_, _, let settings): 133 | return settings 134 | } 135 | } 136 | 137 | var fileURL: URL? { 138 | switch self { 139 | case .normal: 140 | return nil 141 | case .custom(let fileURL, _, _): 142 | return fileURL 143 | } 144 | } 145 | 146 | var type: String { 147 | switch self { 148 | case .normal: 149 | return "m4a" 150 | case .custom(_, let type, _): 151 | return type 152 | } 153 | } 154 | } 155 | 156 | public class func startRecordAudio(forUsage usage: Usage, categoryOptions: AVAudioSessionCategoryOptions = [], withDecibelSamplePeriodicReport decibelSamplePeriodicReport: PeriodicReport) throws { 157 | do { 158 | let session = AVAudioSession.sharedInstance() 159 | let mixWithOthersWhenRecording = categoryOptions.contains(.mixWithOthers) 160 | if mixWithOthersWhenRecording { 161 | if session.category != AVAudioSessionCategoryPlayAndRecord || session.categoryOptions != categoryOptions { 162 | try session.setCategory(AVAudioSessionCategoryPlayAndRecord, with: categoryOptions) 163 | } 164 | } else { 165 | if session.category != AVAudioSessionCategoryRecord { 166 | try session.setCategory(AVAudioSessionCategoryRecord, with: categoryOptions) 167 | } 168 | } 169 | try session.setActive(true) 170 | } catch { 171 | throw error 172 | } 173 | if let audioRecorder = sharedBot.audioRecorder, audioRecorder.isRecording { 174 | audioRecorder.stop() 175 | audioRecorder.deleteRecording() 176 | } 177 | guard decibelSamplePeriodicReport.reportingFrequency > 0 else { 178 | throw AudioBotError.invalidReportingFrequency 179 | } 180 | do { 181 | let audioRecorder: AVAudioRecorder 182 | switch usage { 183 | case .normal: 184 | audioRecorder = sharedBot.normalAudioRecorder 185 | case .custom(let fileURL, let type, let settings): 186 | guard let fileURL = (fileURL ?? FileManager.audiobot_audioFileURLWithName(UUID().uuidString, type)) else { 187 | throw AudioBotError.noFileURL 188 | } 189 | audioRecorder = try AVAudioRecorder(url: fileURL, settings: settings) 190 | } 191 | sharedBot.audioRecorder = audioRecorder 192 | audioRecorder.delegate = sharedBot 193 | audioRecorder.isMeteringEnabled = true 194 | } catch { 195 | throw error 196 | } 197 | sharedBot.audioRecorder?.record() 198 | sharedBot.recordingPeriodicReport = decibelSamplePeriodicReport 199 | let timeInterval = 1 / decibelSamplePeriodicReport.reportingFrequency 200 | DispatchQueue.main.async { 201 | let timer = Timer.scheduledTimer(timeInterval: timeInterval, target: sharedBot, selector: #selector(AudioBot.reportRecordingDecibel(_:)), userInfo: nil, repeats: true) 202 | sharedBot.recordingTimer?.invalidate() 203 | sharedBot.recordingTimer = timer 204 | } 205 | } 206 | 207 | @objc fileprivate func reportRecordingDecibel(_ sender: Timer) { 208 | guard let audioRecorder = audioRecorder else { 209 | return 210 | } 211 | audioRecorder.updateMeters() 212 | let normalizedDecibel = pow(10, audioRecorder.averagePower(forChannel: 0) * 0.05) 213 | recordingPeriodicReport?.report(normalizedDecibel) 214 | decibelSamples.append(normalizedDecibel) 215 | AudioBot.reportRecordingDuration?(audioRecorder.currentTime) 216 | } 217 | 218 | public class func stopRecord(_ finish: ResultReport?) { 219 | defer { 220 | sharedBot.clearForRecording() 221 | } 222 | guard let audioRecorder = sharedBot.audioRecorder, audioRecorder.isRecording else { 223 | return 224 | } 225 | let duration = audioRecorder.currentTime 226 | audioRecorder.stop() 227 | finish?(audioRecorder.url, duration, sharedBot.decibelSamples) 228 | sharedBot.deactiveAudioSessionAndNotifyOthers() 229 | } 230 | 231 | public class func removeAudioAtFileURL(_ fileURL: URL) { 232 | FileManager.audiobot_removeAudioAtFileURL(fileURL) 233 | } 234 | 235 | public class func compressDecibelSamples(_ decibelSamples: [Float], withSamplingInterval samplingInterval: Int, minNumberOfDecibelSamples: Int, maxNumberOfDecibelSamples: Int) -> [Float] { 236 | guard samplingInterval > 0 else { 237 | fatalError("Invlid samplingInterval!") 238 | } 239 | guard minNumberOfDecibelSamples > 0 else { 240 | fatalError("Invlid minNumberOfDecibelSamples!") 241 | } 242 | guard maxNumberOfDecibelSamples >= minNumberOfDecibelSamples else { 243 | fatalError("Invlid maxNumberOfDecibelSamples!") 244 | } 245 | guard decibelSamples.count >= minNumberOfDecibelSamples else { 246 | print("Warning: Insufficient number of decibelSamples!") 247 | return decibelSamples 248 | } 249 | func f(_ x: Int, max: Int) -> Int { 250 | let n = 1 - 1 / exp(Double(x) / 100) 251 | return Int(Double(max) * n) 252 | } 253 | let realSamplingInterval = min(samplingInterval, decibelSamples.count / minNumberOfDecibelSamples) 254 | var samples: [Float] = [] 255 | var i = 0 256 | while i < decibelSamples.count { 257 | samples.append(decibelSamples[i]) 258 | i += realSamplingInterval 259 | } 260 | let finalNumber = f(samples.count, max: maxNumberOfDecibelSamples) 261 | func averageSamplingFrom(_ values: [Float], withCount count: Int) -> [Float] { 262 | let step = Double(values.count) / Double(count) 263 | var outputValues = [Float]() 264 | var x: Double = 0 265 | for _ in 0.. vadSettings.silenceVolume { 306 | isValid = true 307 | count = 0 308 | } else if isValid { 309 | count += 1 310 | } 311 | if count > activeCount, isValid { 312 | stopRecord({ (fileURL, duration, decibelSamples) in 313 | recordResultReport(fileURL, duration, decibelSamples) 314 | }) 315 | retry() 316 | } 317 | }) 318 | try startRecordAudio(forUsage: newUsage, withDecibelSamplePeriodicReport: decibelPeriodicReport) 319 | DispatchQueue.main.asyncAfter(deadline: .now() + vadSettings.spaceDuration) { 320 | if !isValid { 321 | stopRecord(nil) 322 | retry() 323 | } 324 | } 325 | } catch { 326 | throw error 327 | } 328 | } 329 | 330 | public class func stopAutomaticRecord() { 331 | stopRecord(nil) 332 | sharedBot.automaticRecordEnable = false 333 | } 334 | } 335 | 336 | // MARK: - Playback 337 | 338 | extension AudioBot { 339 | 340 | public class func startPlayAudioAtFileURL(_ fileURL: URL, fromTime: TimeInterval, categoryOptions: AVAudioSessionCategoryOptions = [], withProgressPeriodicReport progressPeriodicReport: PeriodicReport, finish: @escaping (Bool) -> Void) throws { 341 | let session = AVAudioSession.sharedInstance() 342 | do { 343 | if #available(iOS 10.0, *) { 344 | try session.setCategory( 345 | AVAudioSessionCategoryPlayAndRecord, 346 | mode: AVAudioSessionModeDefault, 347 | options: categoryOptions 348 | ) 349 | } else { 350 | try session.setCategory(AVAudioSessionCategoryPlayAndRecord) 351 | } 352 | try session.setActive(true) 353 | } catch let error { 354 | throw error 355 | } 356 | guard progressPeriodicReport.reportingFrequency > 0 else { 357 | throw AudioBotError.invalidReportingFrequency 358 | } 359 | if let audioPlayer = sharedBot.audioPlayer, audioPlayer.url == fileURL, abs(fromTime - audioPlayer.currentTime) < 0.2 { 360 | audioPlayer.play() 361 | } else { 362 | sharedBot.audioPlayer?.pause() 363 | do { 364 | let audioPlayer = try AVAudioPlayer(contentsOf: fileURL) 365 | sharedBot.audioPlayer = audioPlayer 366 | audioPlayer.delegate = sharedBot 367 | audioPlayer.prepareToPlay() 368 | audioPlayer.currentTime = fromTime 369 | audioPlayer.play() 370 | } catch { 371 | throw error 372 | } 373 | } 374 | sharedBot.playingPeriodicReport = progressPeriodicReport 375 | sharedBot.playingFinish = finish 376 | let timeInterval = 1 / progressPeriodicReport.reportingFrequency 377 | DispatchQueue.main.async { 378 | let timer = Timer( 379 | timeInterval: timeInterval, 380 | target: sharedBot, 381 | selector: #selector(AudioBot.reportPlayingProgress(_:)), 382 | userInfo: nil, 383 | repeats: true 384 | ) 385 | RunLoop.main.add(timer, forMode: .commonModes) 386 | sharedBot.playingTimer?.invalidate() 387 | sharedBot.playingTimer = timer 388 | } 389 | } 390 | 391 | @objc fileprivate func reportPlayingProgress(_ sender: Timer) { 392 | guard let audioPlayer = audioPlayer else { 393 | return 394 | } 395 | let progress = audioPlayer.currentTime / audioPlayer.duration 396 | playingPeriodicReport?.report(Float(progress)) 397 | AudioBot.reportPlayingDuration?(audioPlayer.currentTime) 398 | } 399 | 400 | public class func pausePlay(deactiveAndNotifyOthers: Bool = true) { 401 | sharedBot.clearForPlaying(finish: false) 402 | sharedBot.audioPlayer?.pause() 403 | if deactiveAndNotifyOthers { 404 | sharedBot.deactiveAudioSessionAndNotifyOthers() 405 | } 406 | } 407 | 408 | public class func stopPlay(deactiveAndNotifyOthers: Bool = true) { 409 | sharedBot.clearForPlaying(finish: true) 410 | sharedBot.audioPlayer?.stop() 411 | sharedBot.playingFinish?(false) 412 | sharedBot.playingFinish = nil 413 | if deactiveAndNotifyOthers { 414 | sharedBot.deactiveAudioSessionAndNotifyOthers() 415 | } 416 | } 417 | } 418 | 419 | // MARK: - AVAudioRecorderDelegate 420 | 421 | extension AudioBot: AVAudioRecorderDelegate { 422 | 423 | public func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool) { 424 | print("AudioBot audioRecorderDidFinishRecording: \(flag)") 425 | } 426 | 427 | public func audioRecorderEncodeErrorDidOccur(_ recorder: AVAudioRecorder, error: Error?) { 428 | error.flatMap { 429 | print("AudioBot audioRecorderEncodeErrorDidOccur: \($0)") 430 | } 431 | if let fileURL = AudioBot.recordingFileURL { 432 | AudioBot.removeAudioAtFileURL(fileURL) 433 | } 434 | clearForRecording() 435 | } 436 | } 437 | 438 | // MARK: - AVAudioPlayerDelegate 439 | 440 | extension AudioBot: AVAudioPlayerDelegate { 441 | 442 | public func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) { 443 | print("AudioBot audioPlayerDidFinishPlaying: \(flag)") 444 | clearForPlaying(finish: true) 445 | playingFinish?(true) 446 | playingFinish = nil 447 | deactiveAudioSessionAndNotifyOthers() 448 | } 449 | 450 | public func audioPlayerDecodeErrorDidOccur(_ player: AVAudioPlayer, error: Error?) { 451 | error.flatMap { 452 | print("AudioBot audioPlayerDecodeErrorDidOccur: \($0)") 453 | } 454 | clearForPlaying(finish: true) 455 | playingFinish?(false) 456 | playingFinish = nil 457 | deactiveAudioSessionAndNotifyOthers() 458 | } 459 | } 460 | -------------------------------------------------------------------------------- /AudioBot/FileManager+AudioBot.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FileManager+AudioBot.swift 3 | // AudioBot 4 | // 5 | // Created by NIX on 15/11/28. 6 | // Copyright © 2015年 nixWork. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension FileManager { 12 | 13 | class func audiobot_cachesURL() -> URL { 14 | do { 15 | return try FileManager.default.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: false) 16 | } catch { 17 | fatalError("AudioBot: \(error)") 18 | } 19 | } 20 | 21 | class func audiobot_audioCachesURL() -> URL? { 22 | let audioCachesURL = audiobot_cachesURL().appendingPathComponent("audiobot_audios", isDirectory: true) 23 | let fileManager = FileManager.default 24 | do { 25 | try fileManager.createDirectory(at: audioCachesURL, withIntermediateDirectories: true, attributes: nil) 26 | return audioCachesURL 27 | } catch { 28 | print("AudioBot: \(error)") 29 | } 30 | return nil 31 | } 32 | 33 | class func audiobot_audioFileURLWithName(_ name: String, _ type: String) -> URL? { 34 | if let audioCachesURL = audiobot_audioCachesURL() { 35 | return audioCachesURL.appendingPathComponent("\(name).\(type)") 36 | } 37 | return nil 38 | } 39 | 40 | class func audiobot_removeAudioAtFileURL(_ fileURL: URL) { 41 | do { 42 | try FileManager.default.removeItem(at: fileURL) 43 | } catch { 44 | print("AudioBot: \(error)") 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AudioBot/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.2.2 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2018 nixzhu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 |

5 | 6 | # AudioBot 7 | 8 | AudioBot helps you do audio record & playback. 9 | 10 | ## Requirements 11 | 12 | Swift 4, iOS 8 13 | 14 | - Swift 2.3, use version 0.5.0 15 | - Swift 3.0, use version 1.1.0 16 | - Swift 3.1, use version 1.1.1 17 | 18 | ## Usage 19 | 20 | See the demo. 21 | 22 | ## Installation 23 | 24 | ### Carthage 25 | 26 | ```ogdl 27 | github "nixzhu/AudioBot" 28 | ``` 29 | 30 | ### CocoaPods 31 | 32 | ```ruby 33 | pod 'AudioBot' 34 | ``` 35 | 36 | ## Contact 37 | 38 | NIX [@nixzhu](https://twitter.com/nixzhu) 39 | 40 | ## License 41 | 42 | AudioBot is available under the MIT license. See the LICENSE file for more info. 43 | -------------------------------------------------------------------------------- /VoiceMemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 503B0D371C0948A10053F2B5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503B0D361C0948A10053F2B5 /* AppDelegate.swift */; }; 11 | 503B0D391C0948A10053F2B5 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503B0D381C0948A10053F2B5 /* ViewController.swift */; }; 12 | 503B0D3C1C0948A10053F2B5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 503B0D3A1C0948A10053F2B5 /* Main.storyboard */; }; 13 | 503B0D3E1C0948A20053F2B5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 503B0D3D1C0948A20053F2B5 /* Assets.xcassets */; }; 14 | 503B0D411C0948A20053F2B5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 503B0D3F1C0948A20053F2B5 /* LaunchScreen.storyboard */; }; 15 | 503B0D501C0949490053F2B5 /* AudioBot.h in Headers */ = {isa = PBXBuildFile; fileRef = 503B0D4F1C0949490053F2B5 /* AudioBot.h */; settings = {ATTRIBUTES = (Public, ); }; }; 16 | 503B0D541C0949490053F2B5 /* AudioBot.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 503B0D4D1C0949490053F2B5 /* AudioBot.framework */; }; 17 | 503B0D551C0949490053F2B5 /* AudioBot.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 503B0D4D1C0949490053F2B5 /* AudioBot.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 18 | 503B0D5B1C09497D0053F2B5 /* AudioBot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503B0D5A1C09497D0053F2B5 /* AudioBot.swift */; }; 19 | 503B0D5D1C09B9600053F2B5 /* FileManager+AudioBot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503B0D5C1C09B9600053F2B5 /* FileManager+AudioBot.swift */; }; 20 | 503B0D5F1C09BD0A0053F2B5 /* VoiceMemoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503B0D5E1C09BD0A0053F2B5 /* VoiceMemoCell.swift */; }; 21 | 503B0D611C09C0BD0053F2B5 /* VoiceMemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503B0D601C09C0BD0053F2B5 /* VoiceMemo.swift */; }; 22 | 50E431DD1C2D1E1900FE64BF /* RecordButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E431DC1C2D1E1900FE64BF /* RecordButton.swift */; }; 23 | 50E49A9F1E2CA62400D2C3BA /* FileManager+VoiceMemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E49A9E1E2CA62400D2C3BA /* FileManager+VoiceMemo.swift */; }; 24 | 637F84251E138A06001132C0 /* Waver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637F84241E138A06001132C0 /* Waver.swift */; }; 25 | /* End PBXBuildFile section */ 26 | 27 | /* Begin PBXContainerItemProxy section */ 28 | 503B0D521C0949490053F2B5 /* PBXContainerItemProxy */ = { 29 | isa = PBXContainerItemProxy; 30 | containerPortal = 503B0D2B1C0948A10053F2B5 /* Project object */; 31 | proxyType = 1; 32 | remoteGlobalIDString = 503B0D4C1C0949490053F2B5; 33 | remoteInfo = AudioBot; 34 | }; 35 | /* End PBXContainerItemProxy section */ 36 | 37 | /* Begin PBXCopyFilesBuildPhase section */ 38 | 503B0D591C0949490053F2B5 /* Embed Frameworks */ = { 39 | isa = PBXCopyFilesBuildPhase; 40 | buildActionMask = 2147483647; 41 | dstPath = ""; 42 | dstSubfolderSpec = 10; 43 | files = ( 44 | 503B0D551C0949490053F2B5 /* AudioBot.framework in Embed Frameworks */, 45 | ); 46 | name = "Embed Frameworks"; 47 | runOnlyForDeploymentPostprocessing = 0; 48 | }; 49 | /* End PBXCopyFilesBuildPhase section */ 50 | 51 | /* Begin PBXFileReference section */ 52 | 503B0D331C0948A10053F2B5 /* VoiceMemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VoiceMemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 503B0D361C0948A10053F2B5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 54 | 503B0D381C0948A10053F2B5 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 55 | 503B0D3B1C0948A10053F2B5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 56 | 503B0D3D1C0948A20053F2B5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 57 | 503B0D401C0948A20053F2B5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 58 | 503B0D421C0948A20053F2B5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 59 | 503B0D4D1C0949490053F2B5 /* AudioBot.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AudioBot.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 60 | 503B0D4F1C0949490053F2B5 /* AudioBot.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioBot.h; sourceTree = ""; }; 61 | 503B0D511C0949490053F2B5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 62 | 503B0D5A1C09497D0053F2B5 /* AudioBot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AudioBot.swift; sourceTree = ""; }; 63 | 503B0D5C1C09B9600053F2B5 /* FileManager+AudioBot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FileManager+AudioBot.swift"; sourceTree = ""; }; 64 | 503B0D5E1C09BD0A0053F2B5 /* VoiceMemoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VoiceMemoCell.swift; sourceTree = ""; }; 65 | 503B0D601C09C0BD0053F2B5 /* VoiceMemo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VoiceMemo.swift; sourceTree = ""; }; 66 | 50E431DC1C2D1E1900FE64BF /* RecordButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordButton.swift; sourceTree = ""; }; 67 | 50E49A9E1E2CA62400D2C3BA /* FileManager+VoiceMemo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FileManager+VoiceMemo.swift"; sourceTree = ""; }; 68 | 637F84241E138A06001132C0 /* Waver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Waver.swift; sourceTree = ""; }; 69 | /* End PBXFileReference section */ 70 | 71 | /* Begin PBXFrameworksBuildPhase section */ 72 | 503B0D301C0948A10053F2B5 /* Frameworks */ = { 73 | isa = PBXFrameworksBuildPhase; 74 | buildActionMask = 2147483647; 75 | files = ( 76 | 503B0D541C0949490053F2B5 /* AudioBot.framework in Frameworks */, 77 | ); 78 | runOnlyForDeploymentPostprocessing = 0; 79 | }; 80 | 503B0D491C0949490053F2B5 /* Frameworks */ = { 81 | isa = PBXFrameworksBuildPhase; 82 | buildActionMask = 2147483647; 83 | files = ( 84 | ); 85 | runOnlyForDeploymentPostprocessing = 0; 86 | }; 87 | /* End PBXFrameworksBuildPhase section */ 88 | 89 | /* Begin PBXGroup section */ 90 | 503B0D2A1C0948A10053F2B5 = { 91 | isa = PBXGroup; 92 | children = ( 93 | 503B0D351C0948A10053F2B5 /* VoiceMemo */, 94 | 503B0D4E1C0949490053F2B5 /* AudioBot */, 95 | 503B0D341C0948A10053F2B5 /* Products */, 96 | ); 97 | sourceTree = ""; 98 | }; 99 | 503B0D341C0948A10053F2B5 /* Products */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | 503B0D331C0948A10053F2B5 /* VoiceMemo.app */, 103 | 503B0D4D1C0949490053F2B5 /* AudioBot.framework */, 104 | ); 105 | name = Products; 106 | sourceTree = ""; 107 | }; 108 | 503B0D351C0948A10053F2B5 /* VoiceMemo */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 503B0D361C0948A10053F2B5 /* AppDelegate.swift */, 112 | 503B0D601C09C0BD0053F2B5 /* VoiceMemo.swift */, 113 | 503B0D5E1C09BD0A0053F2B5 /* VoiceMemoCell.swift */, 114 | 50E431DC1C2D1E1900FE64BF /* RecordButton.swift */, 115 | 637F84241E138A06001132C0 /* Waver.swift */, 116 | 503B0D381C0948A10053F2B5 /* ViewController.swift */, 117 | 50E49A9E1E2CA62400D2C3BA /* FileManager+VoiceMemo.swift */, 118 | 503B0D3A1C0948A10053F2B5 /* Main.storyboard */, 119 | 503B0D3D1C0948A20053F2B5 /* Assets.xcassets */, 120 | 503B0D3F1C0948A20053F2B5 /* LaunchScreen.storyboard */, 121 | 503B0D421C0948A20053F2B5 /* Info.plist */, 122 | ); 123 | path = VoiceMemo; 124 | sourceTree = ""; 125 | }; 126 | 503B0D4E1C0949490053F2B5 /* AudioBot */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | 503B0D4F1C0949490053F2B5 /* AudioBot.h */, 130 | 503B0D5A1C09497D0053F2B5 /* AudioBot.swift */, 131 | 503B0D5C1C09B9600053F2B5 /* FileManager+AudioBot.swift */, 132 | 503B0D511C0949490053F2B5 /* Info.plist */, 133 | ); 134 | path = AudioBot; 135 | sourceTree = ""; 136 | }; 137 | /* End PBXGroup section */ 138 | 139 | /* Begin PBXHeadersBuildPhase section */ 140 | 503B0D4A1C0949490053F2B5 /* Headers */ = { 141 | isa = PBXHeadersBuildPhase; 142 | buildActionMask = 2147483647; 143 | files = ( 144 | 503B0D501C0949490053F2B5 /* AudioBot.h in Headers */, 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | /* End PBXHeadersBuildPhase section */ 149 | 150 | /* Begin PBXNativeTarget section */ 151 | 503B0D321C0948A10053F2B5 /* VoiceMemo */ = { 152 | isa = PBXNativeTarget; 153 | buildConfigurationList = 503B0D451C0948A20053F2B5 /* Build configuration list for PBXNativeTarget "VoiceMemo" */; 154 | buildPhases = ( 155 | 503B0D2F1C0948A10053F2B5 /* Sources */, 156 | 503B0D301C0948A10053F2B5 /* Frameworks */, 157 | 503B0D311C0948A10053F2B5 /* Resources */, 158 | 503B0D591C0949490053F2B5 /* Embed Frameworks */, 159 | ); 160 | buildRules = ( 161 | ); 162 | dependencies = ( 163 | 503B0D531C0949490053F2B5 /* PBXTargetDependency */, 164 | ); 165 | name = VoiceMemo; 166 | productName = VoiceMemo; 167 | productReference = 503B0D331C0948A10053F2B5 /* VoiceMemo.app */; 168 | productType = "com.apple.product-type.application"; 169 | }; 170 | 503B0D4C1C0949490053F2B5 /* AudioBot */ = { 171 | isa = PBXNativeTarget; 172 | buildConfigurationList = 503B0D581C0949490053F2B5 /* Build configuration list for PBXNativeTarget "AudioBot" */; 173 | buildPhases = ( 174 | 503B0D481C0949490053F2B5 /* Sources */, 175 | 503B0D491C0949490053F2B5 /* Frameworks */, 176 | 503B0D4A1C0949490053F2B5 /* Headers */, 177 | 503B0D4B1C0949490053F2B5 /* Resources */, 178 | ); 179 | buildRules = ( 180 | ); 181 | dependencies = ( 182 | ); 183 | name = AudioBot; 184 | productName = AudioBot; 185 | productReference = 503B0D4D1C0949490053F2B5 /* AudioBot.framework */; 186 | productType = "com.apple.product-type.framework"; 187 | }; 188 | /* End PBXNativeTarget section */ 189 | 190 | /* Begin PBXProject section */ 191 | 503B0D2B1C0948A10053F2B5 /* Project object */ = { 192 | isa = PBXProject; 193 | attributes = { 194 | LastSwiftUpdateCheck = 0710; 195 | LastUpgradeCheck = 0900; 196 | ORGANIZATIONNAME = nixWork; 197 | TargetAttributes = { 198 | 503B0D321C0948A10053F2B5 = { 199 | CreatedOnToolsVersion = 7.1.1; 200 | DevelopmentTeam = 8D957V42M6; 201 | LastSwiftMigration = 0800; 202 | }; 203 | 503B0D4C1C0949490053F2B5 = { 204 | CreatedOnToolsVersion = 7.1.1; 205 | LastSwiftMigration = 0800; 206 | }; 207 | }; 208 | }; 209 | buildConfigurationList = 503B0D2E1C0948A10053F2B5 /* Build configuration list for PBXProject "VoiceMemo" */; 210 | compatibilityVersion = "Xcode 3.2"; 211 | developmentRegion = English; 212 | hasScannedForEncodings = 0; 213 | knownRegions = ( 214 | en, 215 | Base, 216 | ); 217 | mainGroup = 503B0D2A1C0948A10053F2B5; 218 | productRefGroup = 503B0D341C0948A10053F2B5 /* Products */; 219 | projectDirPath = ""; 220 | projectRoot = ""; 221 | targets = ( 222 | 503B0D321C0948A10053F2B5 /* VoiceMemo */, 223 | 503B0D4C1C0949490053F2B5 /* AudioBot */, 224 | ); 225 | }; 226 | /* End PBXProject section */ 227 | 228 | /* Begin PBXResourcesBuildPhase section */ 229 | 503B0D311C0948A10053F2B5 /* Resources */ = { 230 | isa = PBXResourcesBuildPhase; 231 | buildActionMask = 2147483647; 232 | files = ( 233 | 503B0D411C0948A20053F2B5 /* LaunchScreen.storyboard in Resources */, 234 | 503B0D3E1C0948A20053F2B5 /* Assets.xcassets in Resources */, 235 | 503B0D3C1C0948A10053F2B5 /* Main.storyboard in Resources */, 236 | ); 237 | runOnlyForDeploymentPostprocessing = 0; 238 | }; 239 | 503B0D4B1C0949490053F2B5 /* Resources */ = { 240 | isa = PBXResourcesBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | ); 244 | runOnlyForDeploymentPostprocessing = 0; 245 | }; 246 | /* End PBXResourcesBuildPhase section */ 247 | 248 | /* Begin PBXSourcesBuildPhase section */ 249 | 503B0D2F1C0948A10053F2B5 /* Sources */ = { 250 | isa = PBXSourcesBuildPhase; 251 | buildActionMask = 2147483647; 252 | files = ( 253 | 503B0D391C0948A10053F2B5 /* ViewController.swift in Sources */, 254 | 637F84251E138A06001132C0 /* Waver.swift in Sources */, 255 | 50E49A9F1E2CA62400D2C3BA /* FileManager+VoiceMemo.swift in Sources */, 256 | 503B0D5F1C09BD0A0053F2B5 /* VoiceMemoCell.swift in Sources */, 257 | 503B0D611C09C0BD0053F2B5 /* VoiceMemo.swift in Sources */, 258 | 503B0D371C0948A10053F2B5 /* AppDelegate.swift in Sources */, 259 | 50E431DD1C2D1E1900FE64BF /* RecordButton.swift in Sources */, 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | }; 263 | 503B0D481C0949490053F2B5 /* Sources */ = { 264 | isa = PBXSourcesBuildPhase; 265 | buildActionMask = 2147483647; 266 | files = ( 267 | 503B0D5B1C09497D0053F2B5 /* AudioBot.swift in Sources */, 268 | 503B0D5D1C09B9600053F2B5 /* FileManager+AudioBot.swift in Sources */, 269 | ); 270 | runOnlyForDeploymentPostprocessing = 0; 271 | }; 272 | /* End PBXSourcesBuildPhase section */ 273 | 274 | /* Begin PBXTargetDependency section */ 275 | 503B0D531C0949490053F2B5 /* PBXTargetDependency */ = { 276 | isa = PBXTargetDependency; 277 | target = 503B0D4C1C0949490053F2B5 /* AudioBot */; 278 | targetProxy = 503B0D521C0949490053F2B5 /* PBXContainerItemProxy */; 279 | }; 280 | /* End PBXTargetDependency section */ 281 | 282 | /* Begin PBXVariantGroup section */ 283 | 503B0D3A1C0948A10053F2B5 /* Main.storyboard */ = { 284 | isa = PBXVariantGroup; 285 | children = ( 286 | 503B0D3B1C0948A10053F2B5 /* Base */, 287 | ); 288 | name = Main.storyboard; 289 | sourceTree = ""; 290 | }; 291 | 503B0D3F1C0948A20053F2B5 /* LaunchScreen.storyboard */ = { 292 | isa = PBXVariantGroup; 293 | children = ( 294 | 503B0D401C0948A20053F2B5 /* Base */, 295 | ); 296 | name = LaunchScreen.storyboard; 297 | sourceTree = ""; 298 | }; 299 | /* End PBXVariantGroup section */ 300 | 301 | /* Begin XCBuildConfiguration section */ 302 | 503B0D431C0948A20053F2B5 /* Debug */ = { 303 | isa = XCBuildConfiguration; 304 | buildSettings = { 305 | ALWAYS_SEARCH_USER_PATHS = NO; 306 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 307 | CLANG_CXX_LIBRARY = "libc++"; 308 | CLANG_ENABLE_MODULES = YES; 309 | CLANG_ENABLE_OBJC_ARC = YES; 310 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 311 | CLANG_WARN_BOOL_CONVERSION = YES; 312 | CLANG_WARN_COMMA = YES; 313 | CLANG_WARN_CONSTANT_CONVERSION = YES; 314 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 315 | CLANG_WARN_EMPTY_BODY = YES; 316 | CLANG_WARN_ENUM_CONVERSION = YES; 317 | CLANG_WARN_INFINITE_RECURSION = YES; 318 | CLANG_WARN_INT_CONVERSION = YES; 319 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 320 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 321 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 322 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 323 | CLANG_WARN_STRICT_PROTOTYPES = YES; 324 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 325 | CLANG_WARN_UNREACHABLE_CODE = YES; 326 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 327 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 328 | COPY_PHASE_STRIP = NO; 329 | DEBUG_INFORMATION_FORMAT = dwarf; 330 | ENABLE_STRICT_OBJC_MSGSEND = YES; 331 | ENABLE_TESTABILITY = YES; 332 | GCC_C_LANGUAGE_STANDARD = gnu99; 333 | GCC_DYNAMIC_NO_PIC = NO; 334 | GCC_NO_COMMON_BLOCKS = YES; 335 | GCC_OPTIMIZATION_LEVEL = 0; 336 | GCC_PREPROCESSOR_DEFINITIONS = ( 337 | "DEBUG=1", 338 | "$(inherited)", 339 | ); 340 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 341 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 342 | GCC_WARN_UNDECLARED_SELECTOR = YES; 343 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 344 | GCC_WARN_UNUSED_FUNCTION = YES; 345 | GCC_WARN_UNUSED_VARIABLE = YES; 346 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 347 | MTL_ENABLE_DEBUG_INFO = YES; 348 | ONLY_ACTIVE_ARCH = YES; 349 | SDKROOT = iphoneos; 350 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 351 | SWIFT_VERSION = 4.0; 352 | TARGETED_DEVICE_FAMILY = "1,2"; 353 | }; 354 | name = Debug; 355 | }; 356 | 503B0D441C0948A20053F2B5 /* Release */ = { 357 | isa = XCBuildConfiguration; 358 | buildSettings = { 359 | ALWAYS_SEARCH_USER_PATHS = NO; 360 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 361 | CLANG_CXX_LIBRARY = "libc++"; 362 | CLANG_ENABLE_MODULES = YES; 363 | CLANG_ENABLE_OBJC_ARC = YES; 364 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 365 | CLANG_WARN_BOOL_CONVERSION = YES; 366 | CLANG_WARN_COMMA = YES; 367 | CLANG_WARN_CONSTANT_CONVERSION = YES; 368 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 369 | CLANG_WARN_EMPTY_BODY = YES; 370 | CLANG_WARN_ENUM_CONVERSION = YES; 371 | CLANG_WARN_INFINITE_RECURSION = YES; 372 | CLANG_WARN_INT_CONVERSION = YES; 373 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 374 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 375 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 376 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 377 | CLANG_WARN_STRICT_PROTOTYPES = YES; 378 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 379 | CLANG_WARN_UNREACHABLE_CODE = YES; 380 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 381 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 382 | COPY_PHASE_STRIP = NO; 383 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 384 | ENABLE_NS_ASSERTIONS = NO; 385 | ENABLE_STRICT_OBJC_MSGSEND = YES; 386 | GCC_C_LANGUAGE_STANDARD = gnu99; 387 | GCC_NO_COMMON_BLOCKS = YES; 388 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 389 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 390 | GCC_WARN_UNDECLARED_SELECTOR = YES; 391 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 392 | GCC_WARN_UNUSED_FUNCTION = YES; 393 | GCC_WARN_UNUSED_VARIABLE = YES; 394 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 395 | MTL_ENABLE_DEBUG_INFO = NO; 396 | SDKROOT = iphoneos; 397 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 398 | SWIFT_VERSION = 4.0; 399 | TARGETED_DEVICE_FAMILY = "1,2"; 400 | VALIDATE_PRODUCT = YES; 401 | }; 402 | name = Release; 403 | }; 404 | 503B0D461C0948A20053F2B5 /* Debug */ = { 405 | isa = XCBuildConfiguration; 406 | buildSettings = { 407 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 408 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 409 | DEVELOPMENT_TEAM = 8D957V42M6; 410 | INFOPLIST_FILE = VoiceMemo/Info.plist; 411 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 412 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 413 | PRODUCT_BUNDLE_IDENTIFIER = com.nixWork.VoiceMemo; 414 | PRODUCT_NAME = "$(TARGET_NAME)"; 415 | SWIFT_VERSION = 4.0; 416 | }; 417 | name = Debug; 418 | }; 419 | 503B0D471C0948A20053F2B5 /* Release */ = { 420 | isa = XCBuildConfiguration; 421 | buildSettings = { 422 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 423 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 424 | DEVELOPMENT_TEAM = 8D957V42M6; 425 | INFOPLIST_FILE = VoiceMemo/Info.plist; 426 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 427 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 428 | PRODUCT_BUNDLE_IDENTIFIER = com.nixWork.VoiceMemo; 429 | PRODUCT_NAME = "$(TARGET_NAME)"; 430 | SWIFT_VERSION = 4.0; 431 | }; 432 | name = Release; 433 | }; 434 | 503B0D561C0949490053F2B5 /* Debug */ = { 435 | isa = XCBuildConfiguration; 436 | buildSettings = { 437 | APPLICATION_EXTENSION_API_ONLY = YES; 438 | CLANG_ENABLE_MODULES = YES; 439 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 440 | CURRENT_PROJECT_VERSION = 1; 441 | DEFINES_MODULE = YES; 442 | DYLIB_COMPATIBILITY_VERSION = 1; 443 | DYLIB_CURRENT_VERSION = 1; 444 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 445 | INFOPLIST_FILE = AudioBot/Info.plist; 446 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 447 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 448 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 449 | PRODUCT_BUNDLE_IDENTIFIER = com.nixWork.AudioBot; 450 | PRODUCT_NAME = "$(TARGET_NAME)"; 451 | SKIP_INSTALL = YES; 452 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 453 | SWIFT_VERSION = 4.0; 454 | VERSIONING_SYSTEM = "apple-generic"; 455 | VERSION_INFO_PREFIX = ""; 456 | }; 457 | name = Debug; 458 | }; 459 | 503B0D571C0949490053F2B5 /* Release */ = { 460 | isa = XCBuildConfiguration; 461 | buildSettings = { 462 | APPLICATION_EXTENSION_API_ONLY = YES; 463 | CLANG_ENABLE_MODULES = YES; 464 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 465 | CURRENT_PROJECT_VERSION = 1; 466 | DEFINES_MODULE = YES; 467 | DYLIB_COMPATIBILITY_VERSION = 1; 468 | DYLIB_CURRENT_VERSION = 1; 469 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 470 | INFOPLIST_FILE = AudioBot/Info.plist; 471 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 472 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 473 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 474 | PRODUCT_BUNDLE_IDENTIFIER = com.nixWork.AudioBot; 475 | PRODUCT_NAME = "$(TARGET_NAME)"; 476 | SKIP_INSTALL = YES; 477 | SWIFT_VERSION = 4.0; 478 | VERSIONING_SYSTEM = "apple-generic"; 479 | VERSION_INFO_PREFIX = ""; 480 | }; 481 | name = Release; 482 | }; 483 | /* End XCBuildConfiguration section */ 484 | 485 | /* Begin XCConfigurationList section */ 486 | 503B0D2E1C0948A10053F2B5 /* Build configuration list for PBXProject "VoiceMemo" */ = { 487 | isa = XCConfigurationList; 488 | buildConfigurations = ( 489 | 503B0D431C0948A20053F2B5 /* Debug */, 490 | 503B0D441C0948A20053F2B5 /* Release */, 491 | ); 492 | defaultConfigurationIsVisible = 0; 493 | defaultConfigurationName = Release; 494 | }; 495 | 503B0D451C0948A20053F2B5 /* Build configuration list for PBXNativeTarget "VoiceMemo" */ = { 496 | isa = XCConfigurationList; 497 | buildConfigurations = ( 498 | 503B0D461C0948A20053F2B5 /* Debug */, 499 | 503B0D471C0948A20053F2B5 /* Release */, 500 | ); 501 | defaultConfigurationIsVisible = 0; 502 | defaultConfigurationName = Release; 503 | }; 504 | 503B0D581C0949490053F2B5 /* Build configuration list for PBXNativeTarget "AudioBot" */ = { 505 | isa = XCConfigurationList; 506 | buildConfigurations = ( 507 | 503B0D561C0949490053F2B5 /* Debug */, 508 | 503B0D571C0949490053F2B5 /* Release */, 509 | ); 510 | defaultConfigurationIsVisible = 0; 511 | defaultConfigurationName = Release; 512 | }; 513 | /* End XCConfigurationList section */ 514 | }; 515 | rootObject = 503B0D2B1C0948A10053F2B5 /* Project object */; 516 | } 517 | -------------------------------------------------------------------------------- /VoiceMemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /VoiceMemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /VoiceMemo.xcodeproj/xcshareddata/xcschemes/AudioBot.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 47 | 48 | 54 | 55 | 56 | 57 | 58 | 59 | 65 | 66 | 72 | 73 | 74 | 75 | 77 | 78 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /VoiceMemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // VoiceMemo 4 | // 5 | // Created by NIX on 15/11/28. 6 | // Copyright © 2015年 nixWork. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /VoiceMemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /VoiceMemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /VoiceMemo/Assets.xcassets/icon_pause.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_pause.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "template" 14 | } 15 | } -------------------------------------------------------------------------------- /VoiceMemo/Assets.xcassets/icon_pause.imageset/icon_pause.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixzhu/AudioBot/fcfb27db77dfb64b1df51e6d0fb1ba7cb4f62204/VoiceMemo/Assets.xcassets/icon_pause.imageset/icon_pause.pdf -------------------------------------------------------------------------------- /VoiceMemo/Assets.xcassets/icon_play.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_play.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "template" 14 | } 15 | } -------------------------------------------------------------------------------- /VoiceMemo/Assets.xcassets/icon_play.imageset/icon_play.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixzhu/AudioBot/fcfb27db77dfb64b1df51e6d0fb1ba7cb4f62204/VoiceMemo/Assets.xcassets/icon_play.imageset/icon_play.pdf -------------------------------------------------------------------------------- /VoiceMemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /VoiceMemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 42 | 48 | 49 | 50 | 51 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /VoiceMemo/FileManager+VoiceMemo.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FileManager+VoiceMemo.swift 3 | // VoiceMemo 4 | // 5 | // Created by nixzhu on 2017/1/16. 6 | // Copyright © 2017年 nixWork. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension FileManager { 12 | 13 | class func voicememo_cachesURL() -> URL { 14 | do { 15 | return try FileManager.default.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: false) 16 | } catch { 17 | fatalError("VoiceMemo: \(error)") 18 | } 19 | } 20 | 21 | class func voicememo_audioCachesURL() -> URL? { 22 | let audioCachesURL = voicememo_cachesURL().appendingPathComponent("voice_memos", isDirectory: true) 23 | let fileManager = FileManager.default 24 | do { 25 | try fileManager.createDirectory(at: audioCachesURL, withIntermediateDirectories: true, attributes: nil) 26 | return audioCachesURL 27 | } catch { 28 | print("VoiceMemo: \(error)") 29 | } 30 | return nil 31 | } 32 | 33 | class func voicememo_audioFileURLWithName(_ name: String, _ type: String) -> URL? { 34 | if let audioCachesURL = voicememo_audioCachesURL() { 35 | return audioCachesURL.appendingPathComponent("\(name).\(type)") 36 | } 37 | return nil 38 | } 39 | 40 | class func voicememo_removeAudioAtFileURL(_ fileURL: URL) { 41 | do { 42 | try FileManager.default.removeItem(at: fileURL) 43 | } catch { 44 | print("VoiceMemo: \(error)") 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /VoiceMemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.2.2 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 31 23 | LSRequiresIPhoneOS 24 | 25 | NSMicrophoneUsageDescription 26 | Record audio 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /VoiceMemo/RecordButton.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RecordButton.swift 3 | // VoiceMemo 4 | // 5 | // Created by NIX on 15/12/25. 6 | // Copyright © 2015年 nixWork. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @IBDesignable 12 | class RecordButton: UIButton { 13 | 14 | override var intrinsicContentSize : CGSize { 15 | return CGSize(width: 100, height: 100) 16 | } 17 | 18 | lazy var outerPath: UIBezierPath = { 19 | return UIBezierPath(ovalIn: self.bounds.insetBy(dx: 8, dy: 8)) 20 | }() 21 | 22 | lazy var innerDefaultPath: UIBezierPath = { 23 | return UIBezierPath(roundedRect: self.bounds.insetBy(dx: 14, dy: 14), cornerRadius: 43) 24 | }() 25 | 26 | lazy var innerRecordingPath: UIBezierPath = { 27 | return UIBezierPath(roundedRect: self.bounds.insetBy(dx: 35, dy: 35), cornerRadius: 5) 28 | }() 29 | 30 | var fromInnerPath: UIBezierPath { 31 | switch appearance { 32 | case .default: 33 | return innerRecordingPath 34 | case .recording: 35 | return innerDefaultPath 36 | } 37 | } 38 | 39 | var toInnerPath: UIBezierPath { 40 | switch appearance { 41 | case .default: 42 | return innerDefaultPath 43 | case .recording: 44 | return innerRecordingPath 45 | } 46 | } 47 | 48 | enum Appearance { 49 | case `default` 50 | case recording 51 | 52 | var fromOuterLineWidth: CGFloat { 53 | switch self { 54 | case .default: 55 | return 3 56 | case .recording: 57 | return 8 58 | } 59 | } 60 | 61 | var toOuterLineWidth: CGFloat { 62 | switch self { 63 | case .default: 64 | return 8 65 | case .recording: 66 | return 3 67 | } 68 | } 69 | 70 | var fromOuterFillColor: UIColor { 71 | switch self { 72 | case .default: 73 | return UIColor(red: 237/255.0, green: 247/255.0, blue: 1, alpha: 1) 74 | case .recording: 75 | return UIColor.white 76 | } 77 | } 78 | 79 | var toOuterFillColor: UIColor { 80 | switch self { 81 | case .default: 82 | return UIColor.white 83 | case .recording: 84 | return UIColor(red: 237/255.0, green: 247/255.0, blue: 1, alpha: 1) 85 | } 86 | } 87 | 88 | var fromInnerFillColor: UIColor { 89 | switch self { 90 | case .default: 91 | return UIColor.red 92 | case .recording: 93 | return UIColor.blue 94 | } 95 | } 96 | 97 | var toInnerFillColor: UIColor { 98 | switch self { 99 | case .default: 100 | return UIColor.blue 101 | case .recording: 102 | return UIColor.red 103 | } 104 | } 105 | } 106 | 107 | var appearance: Appearance = .default { 108 | didSet { 109 | 110 | let duration: TimeInterval = 0.25 111 | 112 | do { 113 | let animation = CABasicAnimation(keyPath: "lineWidth") 114 | animation.fromValue = appearance.fromOuterLineWidth 115 | animation.toValue = appearance.toOuterLineWidth 116 | animation.duration = duration 117 | animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) 118 | animation.fillMode = kCAFillModeBoth 119 | animation.isRemovedOnCompletion = false 120 | 121 | outerShapeLayer.add(animation, forKey: "lineWidth") 122 | } 123 | 124 | do { 125 | let animation = CABasicAnimation(keyPath: "fillColor") 126 | animation.fromValue = appearance.fromOuterFillColor.cgColor 127 | animation.toValue = appearance.toOuterFillColor.cgColor 128 | animation.duration = duration 129 | animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) 130 | animation.fillMode = kCAFillModeBoth 131 | animation.isRemovedOnCompletion = false 132 | 133 | outerShapeLayer.add(animation, forKey: "fillColor") 134 | } 135 | 136 | do { 137 | let animation = CABasicAnimation(keyPath: "path") 138 | 139 | animation.fromValue = fromInnerPath.cgPath 140 | animation.toValue = toInnerPath.cgPath 141 | animation.duration = duration 142 | animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) 143 | animation.fillMode = kCAFillModeBoth 144 | animation.isRemovedOnCompletion = false 145 | 146 | innerShapeLayer.add(animation, forKey: "path") 147 | } 148 | 149 | do { 150 | let animation = CABasicAnimation(keyPath: "fillColor") 151 | animation.fromValue = appearance.fromInnerFillColor.cgColor 152 | animation.toValue = appearance.toInnerFillColor.cgColor 153 | animation.duration = duration 154 | animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) 155 | animation.fillMode = kCAFillModeBoth 156 | animation.isRemovedOnCompletion = false 157 | 158 | innerShapeLayer.add(animation, forKey: "fillColor") 159 | } 160 | } 161 | } 162 | 163 | lazy var outerShapeLayer: CAShapeLayer = { 164 | let layer = CAShapeLayer() 165 | layer.path = self.outerPath.cgPath 166 | layer.lineWidth = self.appearance.toOuterLineWidth 167 | layer.strokeColor = UIColor.blue.cgColor 168 | layer.fillColor = self.appearance.toOuterFillColor.cgColor 169 | layer.fillRule = kCAFillRuleEvenOdd 170 | layer.contentsScale = UIScreen.main.scale 171 | return layer 172 | }() 173 | 174 | lazy var innerShapeLayer: CAShapeLayer = { 175 | let layer = CAShapeLayer() 176 | layer.path = self.toInnerPath.cgPath 177 | layer.fillColor = self.appearance.toInnerFillColor.cgColor 178 | layer.fillRule = kCAFillRuleEvenOdd 179 | layer.contentsScale = UIScreen.main.scale 180 | return layer 181 | }() 182 | 183 | override func didMoveToSuperview() { 184 | super.didMoveToSuperview() 185 | 186 | layer.addSublayer(outerShapeLayer) 187 | layer.addSublayer(innerShapeLayer) 188 | } 189 | } 190 | 191 | -------------------------------------------------------------------------------- /VoiceMemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // VoiceMemo 4 | // 5 | // Created by NIX on 15/11/28. 6 | // Copyright © 2015年 nixWork. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import AudioBot 11 | import AVFoundation 12 | 13 | class ViewController: UIViewController { 14 | 15 | @IBOutlet weak var voiceMemosTableView: UITableView! 16 | @IBOutlet weak var recordButton: RecordButton! 17 | @IBOutlet weak var modeSegmentedControl: UISegmentedControl! 18 | @IBOutlet weak var waver: Waver! 19 | @IBOutlet weak var waverBottom: NSLayoutConstraint! 20 | @IBOutlet weak var buttonBottom: NSLayoutConstraint! 21 | 22 | var bottomConstrains: [NSLayoutConstraint] { 23 | return [self.buttonBottom, self.waverBottom] 24 | } 25 | 26 | var voiceMemos: [VoiceMemo] = [] 27 | 28 | override func viewDidLoad() { 29 | super.viewDidLoad() 30 | 31 | AudioBot.prepareForNormalRecord() 32 | } 33 | 34 | @IBAction func modeChangeAction(_ sender: Any) { 35 | let startConstant: CGFloat = 0 36 | let endConstant: CGFloat = -128.0 37 | let animationDuration: TimeInterval = 0.3 38 | let index = modeSegmentedControl.selectedSegmentIndex 39 | self.bottomConstrains[1 - index].constant = endConstant 40 | UIView.animate(withDuration: animationDuration, animations: { 41 | self.view.layoutIfNeeded() 42 | }, completion: { (finished) in 43 | if finished { 44 | self.bottomConstrains[index].constant = startConstant 45 | UIView.animate(withDuration: animationDuration, animations: { 46 | self.view.layoutIfNeeded() 47 | }) 48 | } 49 | }) 50 | if index == 1 { 51 | do { 52 | self.waver.waverCallback = { _ in } 53 | let decibelSamplePeriodicReport: AudioBot.PeriodicReport = (reportingFrequency: 60, report: { decibelSample in 54 | print("decibelSample: \(decibelSample)") 55 | self.waver.level = CGFloat(decibelSample) 56 | }) 57 | let vadSettings = VADSettings() 58 | vadSettings.silenceDuration = 0.75 59 | vadSettings.silenceVolume = 0.05 60 | let usage = AudioBot.Usage.custom(fileURL: nil, type: "wav", settings: AudioBot.Usage.wavSettings) 61 | try AudioBot.startAutomaticRecordAudio(forUsage: usage, withVADSettings: vadSettings, decibelSamplePeriodicReport: decibelSamplePeriodicReport) { [weak self] (fileURL, duration, decibelSamples) in 62 | print("fileURL: \(fileURL)") 63 | print("duration: \(duration)") 64 | print("decibelSamples: \(decibelSamples)") 65 | if duration < 2.5 { return } 66 | guard let newFileURL = FileManager.voicememo_audioFileURLWithName(UUID().uuidString, "wav") else { return } 67 | guard let _ = try? FileManager.default.copyItem(at: fileURL, to: newFileURL) else { return } 68 | let voiceMemo = VoiceMemo(fileURL: newFileURL, duration: duration) 69 | self?.voiceMemos.append(voiceMemo) 70 | self?.voiceMemosTableView.reloadData() 71 | } 72 | } catch { 73 | print("record error: \(error)") 74 | } 75 | } else { 76 | AudioBot.stopAutomaticRecord() 77 | } 78 | } 79 | 80 | @IBAction func record(_ sender: UIButton) { 81 | if AudioBot.isRecording { 82 | AudioBot.stopRecord { [weak self] fileURL, duration, decibelSamples in 83 | print("fileURL: \(fileURL)") 84 | print("duration: \(duration)") 85 | print("decibelSamples: \(decibelSamples)") 86 | guard let newFileURL = FileManager.voicememo_audioFileURLWithName(UUID().uuidString, "m4a") else { return } 87 | guard let _ = try? FileManager.default.copyItem(at: fileURL, to: newFileURL) else { return } 88 | let voiceMemo = VoiceMemo(fileURL: newFileURL, duration: duration) 89 | self?.voiceMemos.append(voiceMemo) 90 | self?.voiceMemosTableView.reloadData() 91 | } 92 | recordButton.appearance = .default 93 | } else { 94 | do { 95 | let decibelSamplePeriodicReport: AudioBot.PeriodicReport = (reportingFrequency: 10, report: { decibelSample in 96 | print("decibelSample: \(decibelSample)") 97 | }) 98 | try AudioBot.startRecordAudio(forUsage: .normal, withDecibelSamplePeriodicReport: decibelSamplePeriodicReport) 99 | recordButton.appearance = .recording 100 | } catch { 101 | print("record error: \(error)") 102 | } 103 | } 104 | } 105 | } 106 | 107 | extension ViewController: UITableViewDataSource, UITableViewDelegate { 108 | 109 | func numberOfSections(in tableView: UITableView) -> Int { 110 | return 1 111 | } 112 | 113 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 114 | return voiceMemos.count 115 | } 116 | 117 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 118 | let cell = tableView.dequeueReusableCell(withIdentifier: "VoiceMemoCell") as! VoiceMemoCell 119 | let voiceMemo = voiceMemos[indexPath.row] 120 | cell.configureWithVoiceMemo(voiceMemo) 121 | cell.playOrPauseAction = { [weak self] cell, progressView in 122 | func tryPlay() { 123 | do { 124 | let progressPeriodicReport: AudioBot.PeriodicReport = (reportingFrequency: 10, report: { progress in 125 | print("progress: \(progress)") 126 | voiceMemo.progress = CGFloat(progress) 127 | progressView.progress = progress 128 | }) 129 | let fromTime = TimeInterval(voiceMemo.progress) * voiceMemo.duration 130 | try AudioBot.startPlayAudioAtFileURL(voiceMemo.fileURL, fromTime: fromTime, withProgressPeriodicReport: progressPeriodicReport, finish: { success in 131 | voiceMemo.playing = false 132 | cell.playing = false 133 | }) 134 | voiceMemo.playing = true 135 | cell.playing = true 136 | } catch { 137 | print("play error: \(error)") 138 | } 139 | } 140 | if AudioBot.isPlaying { 141 | AudioBot.pausePlay() 142 | if let strongSelf = self { 143 | for index in 0..<(strongSelf.voiceMemos).count { 144 | let voiceMemo = strongSelf.voiceMemos[index] 145 | if AudioBot.playingFileURL == voiceMemo.fileURL { 146 | let indexPath = IndexPath(row: index, section: 0) 147 | if let cell = tableView.cellForRow(at: indexPath) as? VoiceMemoCell { 148 | voiceMemo.playing = false 149 | cell.playing = false 150 | } 151 | break 152 | } 153 | } 154 | } 155 | if AudioBot.playingFileURL != voiceMemo.fileURL { 156 | tryPlay() 157 | } 158 | } else { 159 | tryPlay() 160 | } 161 | } 162 | return cell 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /VoiceMemo/VoiceMemo.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VoiceMemo.swift 3 | // VoiceMemo 4 | // 5 | // Created by NIX on 15/11/28. 6 | // Copyright © 2015年 nixWork. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class VoiceMemo { 12 | 13 | let fileURL: URL 14 | var duration: TimeInterval 15 | 16 | var progress: CGFloat = 0 17 | var playing: Bool = false 18 | 19 | let createdAt: Date = Date() 20 | 21 | init(fileURL: URL, duration: TimeInterval) { 22 | self.fileURL = fileURL 23 | self.duration = duration 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /VoiceMemo/VoiceMemoCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VoiceMemoCell.swift 3 | // VoiceMemo 4 | // 5 | // Created by NIX on 15/11/28. 6 | // Copyright © 2015年 nixWork. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class VoiceMemoCell: UITableViewCell { 12 | 13 | @IBOutlet weak var playButton: UIButton! 14 | @IBOutlet weak var datetimeLabel: UILabel! 15 | @IBOutlet weak var durationLabel: UILabel! 16 | @IBOutlet weak var progressView: UIProgressView! 17 | 18 | var playing: Bool = false { 19 | willSet { 20 | if newValue != playing { 21 | if newValue { 22 | playButton.setImage(UIImage(named: "icon_pause"), for: UIControlState()) 23 | } else { 24 | playButton.setImage(UIImage(named: "icon_play"), for: UIControlState()) 25 | } 26 | } 27 | } 28 | } 29 | 30 | var playOrPauseAction: ((_ cell: VoiceMemoCell, _ progressView: UIProgressView) -> Void)? 31 | 32 | override func awakeFromNib() { 33 | super.awakeFromNib() 34 | } 35 | 36 | override func setSelected(_ selected: Bool, animated: Bool) { 37 | super.setSelected(selected, animated: animated) 38 | } 39 | 40 | func configureWithVoiceMemo(_ voiceMemo: VoiceMemo) { 41 | 42 | playing = voiceMemo.playing 43 | 44 | datetimeLabel.text = "\(voiceMemo.createdAt)" 45 | 46 | durationLabel.text = String(format: "%.1f", voiceMemo.duration) 47 | 48 | progressView.progress = Float(voiceMemo.progress) 49 | } 50 | 51 | @IBAction func playOrPause(_ sender: UIButton) { 52 | 53 | playOrPauseAction?(self, progressView) 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /VoiceMemo/Waver.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Waver.swift 3 | // Yep 4 | // 5 | // Created by kevinzhow on 15/4/1. 6 | // Copyright (c) 2015年 Catch Inc. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class Waver: UIView { 12 | 13 | fileprivate var displayLink: CADisplayLink? 14 | 15 | fileprivate let numberOfWaves: Int = 5 16 | 17 | fileprivate let waveColor = UIColor.white 18 | 19 | fileprivate var phase: CGFloat = 0 20 | 21 | fileprivate var presented = false 22 | 23 | var level: CGFloat = 0 { 24 | didSet { 25 | self.phase += self.phaseShift // Move the wave 26 | self.amplitude = fmax( level, self.idleAmplitude) 27 | 28 | self.appendValue(pow(CGFloat(level), 3)) 29 | 30 | self.updateMeters() 31 | } 32 | } 33 | 34 | fileprivate let mainWaveWidth: CGFloat = 2.0 35 | 36 | fileprivate let decorativeWavesWidth: CGFloat = 1.0 37 | 38 | fileprivate let idleAmplitude: CGFloat = 0.01 39 | 40 | fileprivate let frequency: CGFloat = 1.2 41 | 42 | internal fileprivate(set) var amplitude: CGFloat = 1.0 43 | 44 | var density: CGFloat = 1.0 45 | 46 | var phaseShift: CGFloat = -0.25 47 | 48 | internal fileprivate(set) var waves: [CAShapeLayer] = [] 49 | 50 | // 51 | 52 | fileprivate var waveHeight: CGFloat! 53 | fileprivate var waveWidth: CGFloat! 54 | fileprivate var waveMid: CGFloat! 55 | fileprivate var maxAmplitude: CGFloat! 56 | 57 | // Sample Data 58 | 59 | fileprivate var waveSampleCount = 0 60 | 61 | fileprivate var waveSamples = [CGFloat]() 62 | 63 | fileprivate var waveTotalCount: CGFloat! 64 | 65 | fileprivate var waveSquareWidth: CGFloat = 2.0 66 | 67 | fileprivate var waveGap: CGFloat = 1.0 68 | 69 | fileprivate var maxSquareWaveLength = 256 70 | 71 | fileprivate let fps = 6 72 | 73 | // 74 | 75 | var waverCallback: ((_ waver: Waver) -> ())? { 76 | didSet { 77 | displayLink?.invalidate() 78 | displayLink = CADisplayLink(target: self, selector: #selector(Waver.callbackWaver)) 79 | displayLink?.add(to: RunLoop.current, forMode: RunLoopMode.commonModes) 80 | 81 | (0..