This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func process(_ samples: [HKQuantitySample], type: HKQuantityTypeIdentifier) { | |
var lastHeartRate = 0.0 | |
for sample in samples { | |
if type == .heartRate { | |
lastHeartRate = sample.quantity.doubleValue(for: heartRateQuantity) | |
} | |
self.value = Int(lastHeartRate) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct PagerManager<Content: View>: View { | |
let pageCount: Int | |
@Binding var currentIndex: Int | |
let content: Content | |
//Set the initial values for the variables | |
init(pageCount: Int, currentIndex: Binding<Int>, @ViewBuilder content: () -> Content) { | |
self.pageCount = pageCount | |
self._currentIndex = currentIndex | |
self.content = content() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State private var currentPage = 0 | |
var body: some View { | |
//Pager Manager | |
VStack{ | |
PagerManager(pageCount: 2, currentIndex: $currentPage) { | |
Text("First page") | |
Text("Second page") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SoundAnalysis | |
class SoundAnalyzerController: UIViewController { | |
private let audioEngine = AVAudioEngine() | |
private var soundClassifier = EmotionModel() | |
var inputFormat: AVAudioFormat! | |
var analyzer: SNAudioStreamAnalyzer! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func startAudioEngine() { | |
do { | |
let request = try SNClassifySoundRequest(mlModel: soundClassifier.model) | |
try analyzer.add(request, withObserver: resultsObserver) | |
} catch { | |
print("Unable to prepare request: \(error.localizedDescription)") | |
return | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol EmotionClassifierDelegate { | |
func displayPredictionResult(identifier: String, confidence: Double) | |
} | |
extension SoundAnalyzerController: EmotionClassifierDelegate { | |
func displayPredictionResult(identifier: String, confidence: Double) { | |
DispatchQueue.main.async { | |
let roundConfidence = Double(round(100*confidence)/100) | |
self.transcriberText.text = ("Recognition: \(identifier) with Confidence \(roundConfidence)") |