Post

Replies

Boosts

Views

Activity

How to reset speechRecognizer
Building a very simple voice-to-text app, which I got from an online demo. What I can't seem to find is how to reset the response back to nil. This demo just keeps transcribing from the very beginning till it finally stalls. While I don't know how if the stall is related to my question, I still need to find out how to code "Ok, got the first 100 words. Reset response text to nil. Continue." func startSpeechRecognition(){ let node = audioEngine.inputNode let recordingFormat = node.outputFormat(forBus: 0) node.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat, block: { (buffer, _) in self.request.append(buffer)}) audioEngine.prepare() do { try audioEngine.start() } catch let error { alertView(message: "audioEngine start error") } guard let myRecognition = SFSpeechRecognizer() else { self.alertView(message: "Recognition is not on your phone") return } if !myRecognition.isAvailable { self.alertView(message: "recognition is not available right now") } task = speechRecognizer?.recognitionTask(with: request, resultHandler: { (response, error) in guard let response = response else { if error != nil { self.alertView(message: error!.localizedDescription.debugDescription) } else { self.alertView(message: "Unknow error in creating task") } return } let message = response.bestTranscription.formattedString self.label.text = message }) }
0
1
860
Dec ’21
Is there a method to close files in Swift? Specifically AVAudioFile files?
I have no problem creating, and writing to AVAudioFiles. do { audioFile = try AVAudioFile(forWriting: destinationPath, settings: format.settings) print ("created: \(curFileLinkName)") } catch { print ("error creating file")} But is there a way to close the file? I've searched and all I could find was this very post on StackOverflow, which makes me wonder.
2
1
1.1k
Jul ’22
LaunchScreen doesn't show on simulator in Xcode 12.4
I just upgraded to Xcode 12.4, created a project using the "app" template, without SwiftUI, I chose Storyboard instead. I placed a small image on the LaunchScreen.storyboard, and an NSLog output in my ViewController. When I run the app on the simulator, the LaunchScreen does not, show, and I do get my NSLog output. So I know the app is running. When run this bare app on my physical iPhone X...I do get the launch screen. So I opened a game app I started under Xcode 11.x. It will show the LaunchScreen on both simulator and my device. I've checked that Launch screen interface file base name is set to LaunchScreen in Info.plist. It's also set under App Icons and Launch Images. Is this some bug?
5
0
2.7k
Feb ’21
My writing the installTap buffer to an AVAudioFile seems to fail data-wise, or at the end
I am trying to save the buffer from my installTap to a file. I do it in chunks of 10 so I'll get a bigger file. When I try to play the written file (from the simulator's directory) QuickTime says that it's not compatible. I have examined the bad m4a file and a working one. There are a lot of zero's in the bad file at the beginning followed by a lot of data. However both files appears to have the same header. A lot of people mention that I have to nil the AudioFile, but: audioFile = nil is not a valid syntax, nor can I file a close method in AudioFile. Here's the complete code, edited into one working file: import UIKit import AVFoundation class ViewController: UIViewController { let audioEngine = AVAudioEngine() var audioFile = AVAudioFile() var x = 0 override func viewDidLoad() { super.viewDidLoad() record() // Do any additional setup after loading the view. } func makeFile(format: AVAudioFormat) { let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first do { _ = try FileManager.default.contentsOfDirectory(at: paths!, includingPropertiesForKeys: nil) } catch { print ("error")} let destinationPath = paths!.appendingPathComponent("audioT.m4a") print ("\(destinationPath)") do { audioFile = try AVAudioFile(forWriting: destinationPath, settings: format.settings) print ("file created") } catch { print ("error creating file")} } func record(){ let node = audioEngine.inputNode let recordingFormat = node.inputFormat(forBus: 0) makeFile(format: recordingFormat) node.installTap(onBus: 0, bufferSize: 8192, format: recordingFormat, block: { [self] (buffer, _) in do { try audioFile.write(from: buffer); print ("buffer filled"); x += 1; print("wrote \(x)") if x > 9 { endThis() } } catch {return};}) audioEngine.prepare() do { try audioEngine.start() } catch let error { print ("oh catch") } } func endThis(){ audioEngine.stop() audioEngine.inputNode.removeTap(onBus: 0) } }
1
0
2.1k
Jan ’22
Getting strange message in debugger since Xcode last updated
Xcode updated yesterday, and am now at Xcode Version 13.3 (13E113) Since then, whenever I debug my app the the simulator, I get the message below. Am curious if I should be concerned. If it makes a difference: Yes, I have an IBM keyboard attached via USB. Also this does not happen when I debug the app on the iPhone itself. 2022-03-15 14:50:45.745237-0400 Hello World[48883:648134] [HardwareKeyboard] -[UIApplication getKeyboardDevicePropertiesForSenderID:shouldUpdate:usingSyntheticEvent:], failed to fetch device property for senderID (778835616971358211) use primary keyboard info instead.
3
1
7.1k
May ’22