import Foundation
import AVFoundation
func intervalTimer(intervals: [(TimeInterval, () -> Void, String)]) {
for interval in intervals {
let (duration, action, intervalName) = interval
print("Interval name: \(intervalName)")
// Convert the interval name to an AVSpeechUtterance
let utterance = AVSpeechUtterance(string: intervalName)
utterance.voice = AVSpeechSynthesisVoice(language: "en")
// Use AVSpeechSynthesizer to speak the utterance
let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(utterance)
// Wait for the specified duration
Thread.sleep(forTimeInterval: duration)
// Perform the action
action()
}
}
// Define the intervals and corresponding actions
let intervals: [(TimeInterval, () -> Void, String)] = [
(10, { print("Interval 0 action") }, "Be ready for nuclei isolation"),
(40, { print("Interval 1 action") }, "Sample 1"),
(40, { print("Interval 2 action") }, "Sample 2"),
(40, { print("Interval 3 action") }, "Sample 3"),
(40, { print("Interval 4 action") }, "Sample 4"),
(20, { print("Interval 5 action") }, "Break time and prepare for adding washing buffer"),
(40, { print("Interval 6 action") }, "Sample 1"),
(40, { print("Interval 7 action") }, "Sample 2"),
(40, { print("Interval 8 action") }, "Sample 3"),
(40, { print("Interval 9 action") }, "Sample 4"),
(10, { print("Interval 10 action") }, "Nuclei isolation is done")
]
// Run the interval timer with the specified intervals
intervalTimer(intervals: intervals)