Skip to content

Instantly share code, notes, and snippets.

recognitionRequest = SFSpeechAudioBufferRecognitionRequest()
let inputNode = self.getInputNode()
guard let recognitionRequest = recognitionRequest else { fatalError("Unable to created a SFSpeechAudioBufferRecognitionRequest object") }
// Configure request so that results are returned before audio recording is finished
recognitionRequest.shouldReportPartialResults = true
let recognizer = SFSpeechRecognizer(locale: Locale(identifier: (self.localeIdentifier)!))
// Setup input source
let audioSession = AVAudioSession.sharedInstance()
do {
//try audioSession.setCategory(AVAudioSessionCategoryRecord, with: .allowBluetooth)
try audioSession.setCategory(AVAudioSessionCategoryRecord)
try audioSession.setMode(AVAudioSessionModeMeasurement)
try audioSession.setActive(true, with: .notifyOthersOnDeactivation)
} catch {
print("audioSession properties weren't set because of an error.")
}
SFSpeechRecognizer.requestAuthorization { [weak self] (authStatus) in
var isAuthorization = false
switch authStatus {
case .authorized:
isAuthorization = true
case .denied:
isAuthorization = false
@SunXiaoShan
SunXiaoShan / VoiceRecognitionPlist.plist
Created January 11, 2018 02:46
Voice Recognition Plist
<key>NSMicrophoneUsageDescription</key> <string>Your microphone will be used to record your speech when you press the "Start Recording" button.</string>
<key>NSSpeechRecognitionUsageDescription</key> <string>Speech recognition will be used to determine which words you speak into this device&apos;s microphone.</string>
@SunXiaoShan
SunXiaoShan / OCLintSample.m
Created January 2, 2018 08:38
OCLintSample
// unused variable
int hello = 999;
// short variable name
int a = 1;
// long variable name
int a0123456789b0123456789c0123456789d0123456789e0123456789f0123456789g0123456789h0123456789i0123456789j0123456789k0123456789k0123456789l0123456789m0123456789n0123456789o0123456789p0123456789q0123456789r0123456789s0123456789t0123456789u0123456789v0123456789w0123456789x0123456789y0123456789z0123456789 = 123;
@SunXiaoShan
SunXiaoShan / demonstrateInputSelection.m
Created December 7, 2017 01:59
Apple example - demonstrateInputSelection
#import <AVFoundation/AVAudioSession.h>
- (void) demonstrateInputSelection
{
NSError* theError = nil;
BOOL result = YES;
AVAudioSession* myAudioSession = [AVAudioSession sharedInstance];
result = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&theError];
@SunXiaoShan
SunXiaoShan / LeakTest.swift
Created December 4, 2017 04:04
LeakTest2
// define object
class LeakObject: NSObject {
var node:LeakObject?
var name:String = ""
init(_ name:String) {
super.init()
self.name = name
self.name == "" ? () : print("Init object - \(self.name)")
}
@SunXiaoShan
SunXiaoShan / LeakTest.swift
Created December 4, 2017 03:59
LeakTest 1
// define object
class LeakObject: NSObject {
var node:LeakObject?
var name:String = ""
init(_ name:String) {
super.init()
self.name = name
self.name == "" ? () : print("Init object - \(self.name)")
}
@SunXiaoShan
SunXiaoShan / DemoWeakTests.swift
Last active December 4, 2017 06:05
DemoSwiftLeak
import XCTest
@testable import DemoWeak
class DemoWeakTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
@SunXiaoShan
SunXiaoShan / OCLintTool.sh
Last active October 16, 2017 23:15
OCLint
# 安裝 Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# 安装 OCLint
brew tap oclint/formulae
brew install oclint
# 安裝 xcpretty
gem install xcpretty