Skip to content

Commit

Permalink
Merge pull request #6 from hewigovens/master
Browse files Browse the repository at this point in the history
Convert to Swift 2 syntax and fix build error with Xcode 7
  • Loading branch information
Bruno Berisso committed Jan 5, 2016
2 parents c090df3 + 3e08dcd commit 135e5ae
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 45 deletions.
19 changes: 10 additions & 9 deletions TLSphinx.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@
9B5187A61B18E1E80000E78D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0630;
LastSwiftMigration = 0720;
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
ORGANIZATIONNAME = "Bruno Berisso";
TargetAttributes = {
9B5187AE1B18E1E80000E78D = {
Expand Down Expand Up @@ -286,6 +288,7 @@
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -375,6 +378,7 @@
"$(PROJECT_DIR)/Sphinx/lib/pocketsphinx",
"$(PROJECT_DIR)/Sphinx/lib/sphinxbase",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.tryolabs.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = Sphinx/include;
Expand Down Expand Up @@ -404,6 +408,7 @@
"$(PROJECT_DIR)/Sphinx/lib/pocketsphinx",
"$(PROJECT_DIR)/Sphinx/lib/sphinxbase",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.tryolabs.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = Sphinx/include;
Expand All @@ -413,10 +418,7 @@
9B5187C91B18E1E80000E78D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -432,17 +434,15 @@
"$(PROJECT_DIR)/Sphinx/lib/pocketsphinx",
"$(PROJECT_DIR)/Sphinx/lib/sphinxbase",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.tryolabs.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
9B5187CA1B18E1E80000E78D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
Expand All @@ -454,6 +454,7 @@
"$(PROJECT_DIR)/Sphinx/lib/pocketsphinx",
"$(PROJECT_DIR)/Sphinx/lib/sphinxbase",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.tryolabs.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
13 changes: 8 additions & 5 deletions TLSphinx.xcodeproj/xcshareddata/xcschemes/TLSphinx.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
LastUpgradeVersion = "0720"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:TLSphinx.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand All @@ -85,10 +88,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
29 changes: 19 additions & 10 deletions TLSphinx/Decoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import AVFoundation
import Sphinx

private enum SpeechStateEnum : Printable {
private enum SpeechStateEnum : CustomStringConvertible {
case Silence
case Speech
case Utterance
Expand Down Expand Up @@ -152,30 +152,39 @@ public class Decoder {

public func startDecodingSpeech (utteranceComplete: (Hypotesis?) -> ()) {

var error: NSErrorPointer = nil
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryRecord, error: error)
let error: NSErrorPointer = nil
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryRecord)
} catch let error1 as NSError {
error.memory = error1
}

if error != nil {
println("Error setting the shared AVAudioSession: \(error)")
print("Error setting the shared AVAudioSession: \(error)")
return
}

let tmpFileName = NSTemporaryDirectory()!.stringByAppendingPathComponent("TLSphinx-\(NSDate.timeIntervalSinceReferenceDate())")
let tmpFileName = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent("TLSphinx-\(NSDate.timeIntervalSinceReferenceDate())")
let tmpAudioFile = NSURL(string: tmpFileName)

let settings: [NSObject : AnyObject] = [
AVFormatIDKey: kAudioFormatLinearPCM,
let settings: [String : AnyObject] = [
AVFormatIDKey: UInt(kAudioFormatLinearPCM),
AVSampleRateKey: 16000.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: false,
AVLinearPCMIsFloatKey: false
]

recorder = AVAudioRecorder(URL: tmpAudioFile, settings: settings, error: error)
do {
recorder = try AVAudioRecorder(URL: tmpAudioFile!, settings: settings)
} catch let error1 as NSError {
error.memory = error1
recorder = nil
}

if error != nil {
println("Error setting the audio recorder: \(error)")
print("Error setting the audio recorder: \(error)")
return
}

Expand All @@ -184,7 +193,7 @@ public class Decoder {

start_utt()

audioFileHandle.readabilityHandler = { (handler: NSFileHandle!) -> Void in
audioFileHandle.readabilityHandler = { (handler: NSFileHandle) -> Void in

let audioData = handler.availableData

Expand Down
2 changes: 1 addition & 1 deletion TLSphinx/Hypotesis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct Hypotesis {
public let score: Int
}

extension Hypotesis : Printable {
extension Hypotesis : CustomStringConvertible {

public var description: String {
get {
Expand Down
2 changes: 1 addition & 1 deletion TLSphinx/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.tryolabs.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
22 changes: 11 additions & 11 deletions TLSphinxTests/Basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class BasicTests: XCTestCase {

if let modelPath = getModelPath() {

let hmm = modelPath.stringByAppendingPathComponent("en-us")
let lm = modelPath.stringByAppendingPathComponent("en-us.lm.dmp")
let dict = modelPath.stringByAppendingPathComponent("cmudict-en-us.dict")
let hmm = (modelPath as NSString).stringByAppendingPathComponent("en-us")
let lm = (modelPath as NSString).stringByAppendingPathComponent("en-us.lm.dmp")
let dict = (modelPath as NSString).stringByAppendingPathComponent("cmudict-en-us.dict")

let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict))

Expand All @@ -38,9 +38,9 @@ class BasicTests: XCTestCase {

if let modelPath = getModelPath() {

let hmm = modelPath.stringByAppendingPathComponent("en-us")
let lm = modelPath.stringByAppendingPathComponent("en-us.lm.dmp")
let dict = modelPath.stringByAppendingPathComponent("cmudict-en-us.dict")
let hmm = (modelPath as NSString).stringByAppendingPathComponent("en-us")
let lm = (modelPath as NSString).stringByAppendingPathComponent("en-us.lm.dmp")
let dict = (modelPath as NSString).stringByAppendingPathComponent("cmudict-en-us.dict")

if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) {
let decoder = Decoder(config:config)
Expand All @@ -59,21 +59,21 @@ class BasicTests: XCTestCase {

if let modelPath = getModelPath() {

let hmm = modelPath.stringByAppendingPathComponent("en-us")
let lm = modelPath.stringByAppendingPathComponent("en-us.lm.dmp")
let dict = modelPath.stringByAppendingPathComponent("cmudict-en-us.dict")
let hmm = (modelPath as NSString).stringByAppendingPathComponent("en-us")
let lm = (modelPath as NSString).stringByAppendingPathComponent("en-us.lm.dmp")
let dict = (modelPath as NSString).stringByAppendingPathComponent("cmudict-en-us.dict")

if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) {
if let decoder = Decoder(config:config) {

let audioFile = modelPath.stringByAppendingPathComponent("goforward.raw")
let audioFile = (modelPath as NSString).stringByAppendingPathComponent("goforward.raw")
let expectation = expectationWithDescription("Decode finish")

decoder.decodeSpeechAtPath(audioFile) {

if let hyp = $0 {

println("Text: \(hyp.text) - Score: \(hyp.score)")
print("Text: \(hyp.text) - Score: \(hyp.score)")
XCTAssert(hyp.text == "go forward ten meters", "Pass")

} else {
Expand Down
2 changes: 1 addition & 1 deletion TLSphinxTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.tryolabs.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
12 changes: 5 additions & 7 deletions TLSphinxTests/LiveDecode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ class LiveDecode: XCTestCase {

if let modelPath = getModelPath() {

let hmm = modelPath.stringByAppendingPathComponent("en-us")
let lm = modelPath.stringByAppendingPathComponent("en-us.lm.dmp")
let dict = modelPath.stringByAppendingPathComponent("cmudict-en-us.dict")
let hmm = (modelPath as NSString).stringByAppendingPathComponent("en-us")
let lm = (modelPath as NSString).stringByAppendingPathComponent("en-us.lm.dmp")
let dict = (modelPath as NSString).stringByAppendingPathComponent("cmudict-en-us.dict")

if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) {

config.showDebugInfo = false

if let decoder = Decoder(config:config) {
decoder.startDecodingSpeech { (hyp) -> () in
println("Utterance: \(hyp)")
print("Utterance: \(hyp)")
}

let expectation = expectationWithDescription("")
Expand All @@ -41,9 +41,7 @@ class LiveDecode: XCTestCase {
expectation.fulfill()
})

waitForExpectationsWithTimeout(NSTimeIntervalSince1970, handler: { (error: NSError!) -> Void in

})
waitForExpectationsWithTimeout(NSTimeIntervalSince1970, handler: nil)
}

} else {
Expand Down

0 comments on commit 135e5ae

Please sign in to comment.