Skip to content

Instantly share code, notes, and snippets.

@shams-ahmed
Created March 31, 2021 21:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shams-ahmed/a59329f79982514f68923b39ccf0b2b8 to your computer and use it in GitHub Desktop.
Save shams-ahmed/a59329f79982514f68923b39ccf0b2b8 to your computer and use it in GitHub Desktop.
Symbl.ai: Complete
let audio = Audio()
let symblAI = SymblAI(with: "enter_token_here")
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Stop audio recording if it has been started
if audio.isRunning {
do {
let sound = try audio.stop()
// recording is not active
// start uploading to symbl.ai
symblAI.upload(sound) { [weak self] result in
switch result {
case .success(let upload):
print(upload)
self?.symblAI.status(for: upload) { status in
print(status)
switch status {
case .completed:
self?.symblAI.transcript(for: upload, { transcript in
print(transcript)
})
case .failed: break
case .scheduled, .in_progress:
// After 3 seconds
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 3) {
self?.symblAI.transcript(for: upload, { transcript in
print(transcript)
})
}
}
}
case .failure(let error):
print(error)
}
}
} catch {
print(error)
}
}
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
// Start audio recording
do {
try audio.start()
// recording is now active
} catch {
print(error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment