Created
March 31, 2021 21:00
-
-
Save shams-ahmed/a59329f79982514f68923b39ccf0b2b8 to your computer and use it in GitHub Desktop.
Symbl.ai: Complete
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
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