Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save seanlilmateus/3144058 to your computer and use it in GitHub Desktop.
Save seanlilmateus/3144058 to your computer and use it in GitHub Desktop.
Integrating RubyMotion and the iSpeech SDK

#Integrating RubyMotion and the iSpeech SDK

As of 19th July 2012, RubyMotion has a couple of issues with external libraries as I discovered when trying the integration, thanks to Laurent, the architect of RubyMotion and with some prompting from Stéphane Wirtel here is the issue and resolution including the code to make the iPhone speak.

Firstly setting up the app, assuming you've already copied the files you need into your vendor/iSpeechSDK directory this is the code needed in the rakefile as per any normal library ...

app.vendor_project('vendor/iSpeechSDK', :static, :products => ["libiSpeechSDK.a"], :headers_dir => "Headers")

However, the bundle file which should be in the directory won't be picked up by RubyMotion which doesn't become apparent until you try and instantiate the object, to avoid this issue move the file iSpeechSDK.bundle into the /resources directory on the project root.

The second problem is that the iSpeechSDK class name starts with a lower-case letter, which is not a valid constant name in Ruby, this won't work ...

@sdk = iSpeechSDK.sharedSDK

Instead do this ...

@sdk = NSClassFromString('iSpeechSDK').sharedSDK

So, that issue is solved, if you paste the following code into your app_delegate then you'll hear some speech

@sdk = NSClassFromString('iSpeechSDK').sharedSDK

@sdk.APIKey = ""

@speach = NSClassFromString('ISSpeechSynthesis').alloc.initWithText("Hello World") errorPointer = Pointer.new(:object) @speach.speak(errorPointer)

@ExistsAndIs1
Copy link

As Laurent pointed out in current version you can use capital I

 class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @sdk = ISpeechSDK.sharedSDK
    @sdk.APIKey = "developerdemokeydeveloperdemokey"
    @speach = NSClassFromString('ISSpeechSynthesis').alloc.initWithText("Hello World") 
    errorPointer = Pointer.new(:object) 
    @speach.speak(errorPointer)   
    true
  end
end
´´´

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment