简体   繁体   中英

How can I use OpenEars in a tweak?

I'm trying to include OpenEars in a theos project I'm making, a tweak for jailbroken iDevices, as I need speech recognition for my tweak. I was able to link the OpenEars framework by putting it in the same folder as my private frameworks, and I'm currently trying to get the tutorial code to work. Here's my current code:

#import <OpenEars/LanguageModelGenerator.h>
#import <OpenEars/PocketsphinxController.h>
#import <OpenEars/AcousticModel.h>

%hook SBLockScreenView

-(void)setCustomSlideToUnlockText:(id)arg1 {

LanguageModelGenerator *lmGenerator = [[LanguageModelGenerator alloc] init];

NSArray *words = [NSArray arrayWithObjects:@"WORD", @"STATEMENT", @"OTHER WORD", @"A PHRASE", nil];
NSString *name = @"NameIWantForMyLanguageModelFiles";

NSError *err = [lmGenerator generateLanguageModelFromArray:words withFilesNamed:name forAcousticModelAtPath:[AcousticModel pathToModel:@"AcousticModelEnglish"]];
//NSError* err = [lmGenerator generateLanguageModelFromArray:words withFilesNamed:name forAcousticModelAtPath:imagePath];
//NSError* err = [[NSError alloc] init];

NSDictionary *languageGeneratorResults = nil;

NSString *lmPath = nil;
NSString *dicPath = nil;

if([err code] == noErr) {
    languageGeneratorResults = [err userInfo];

    lmPath = [languageGeneratorResults objectForKey:@"LMPath"];
    dicPath = [languageGeneratorResults objectForKey:@"DictionaryPath"];
}
else {
    NSLog(@"Error: %@",[err localizedDescription]);
}

%orig;

}

%end

This compiles fine, but when it runs, I get these error messages and my device crashes: "While trying to reference the requested acoustic model bundle which is expected to be at the path (null), no bundle was found. This means that when the listening loop begins, it will crash due to the missing required resources. The problem finding the acoustic model bundle could be because the name of the bundle was not given to this method in a way it can use; for instance, if you are trying to use the English acoustic model and you have added that bundle to your app project, you would invoke this method by passing [AcousticModel pathToAcousticModel:@"AcousticModelEnglish"] (or [AcousticModel pathToAcousticModel:@"AcousticModelSpanish"] for the Spanish bundle), without appending ".bundle" to the end, and making sure that the bundle name is spelled exactly as it appears in the actual bundle name (the bundle can be seen in this distribution's folder "Framework".

If this doesn't fix the problem, it is very likely to be due to the fact that the acoustic model bundle wasn't imported successfully into the root level of your app project and its mainBundle. This usually happens either because the acoustic model bundle was never dragged into your app project when the "Framework" folder was originally supposed to be dragged in, or because it was dragged in but instead of using the setting "Create groups for any added folders" in Xcode's "Add Files" dialog, the option "Create folder references for any added folders" was unintentionally chosen. To fix this, just remove the acoustic model bundle or the "Framework" folder from your app and add it again to your app project with the correct setting of "Create groups for any added folders" in Xcode's "Add Files" dialog."

I also get these messages in my syslog:

May 27 00:54:49 Phillips-iPhone SpringBoard[17785] <Warning>: acousticModelPath is (null)
May 27 00:54:49 Phillips-iPhone SpringBoard[17785] <Warning>: Error: the default phonetic dictionary (null)/LanguageModelGeneratorLookupList.text can't be found in the app bundle but the app is attempting to access it, most likely there will be a crash now.
May 27 00:54:49 Phillips-iPhone SpringBoard[17785] <Warning>: Error while trying to load the pronunciation dictionary: Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x1883cbb0 {NSFilePath=(null)/LanguageModelGeneratorLookupList.text, NSUnderlyingError=0x1883cb40 "The operation couldn’t be completed. No such file or directory"}
May 27 00:54:49 Phillips-iPhone SpringBoard[17785] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid domain=nil in -[NSError initWithDomain:code:userInfo:]'

Any help in getting this working is greatly appreciated. Thanks!

I recently made an OpenEars based iOS tweak and I went through the same problem. Because your tweak is not a normal app, the location that pathToAcousticModel gives will not be correct. The easiest solution is to place the acoustic model bundle in a known location and hard code it.

For example, if you are using theos you can place AcousticModelEnglish.bundle in the folder "layout/Library/OpenEars/". Then replace

[AcousticModel pathToAcousticModel:@"AcousticModelEnglish"]

with

@"/Library/OpenEars/AcousticModelEnglish.bundle"

The easiest solution that I found was dragging the "Framework" folder from the OpenEars library that contains the bundle files to the "Frameworks" folder inside the Xcode project. After dragging, mark the option "copy items if needed".

在此处输入图片说明

It sounds strange in the first look but this solution works and you won't change the code.

You will get a file structure like that:

在此处输入图片说明

You can also remove the oldest references of these libraries under the "Framework" folder to keep your project clean.

Cheers,

David

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM