This tutorial is dedicated to all the google Glass developers who need a custom voice recognition, which work in background and does not pollute the view.

But also for all the GG developers who were adding the GlassVoice.apk into their app and would like to optimise it, reach the max numbers of methods in your project really easily because of this library.

 

PS : I don’t recommend to use the GlassVoice.apk in your library in long term , because you are totally depend of this library, there is no document so … working with this , put you in the blur…

This solution is acceptable if you are working on a MVP, like I did, where you are looking for to deliver a product working quickly.

 

Intro: My story

 

During my past experience, I have worked on a MVP on Google Glass where we needed to implement custom voice recognition.

 

By custom voice recognition, I mean my application needed to recognise when ask for a command to be executed, without displaying the standard “Ok glass”, on the bottom of each view in your app.

In my case, I needed a service in background, which listener to me constantly and trigger the “Ok glass” keyword to execute a command from a given dictionary.

 

I was using a library from the GDK(not documented at all though) and it working perfectly, exactly how I wanted: Having a speech recognition in background, executing my command without pollute my view.

After few updates of the Google Glass (from the XE16 If I remember well), the public library what I was using become private and I was not able to use it anymore.

 

STUCK, I was ! A new solution I needed.

 

Lot of developers on Google Glass found a work around for that, what I followed :

1. Pull the GlassVoice.apk from your Glass: adb pull /system/app/GlassVoice.apk
2. Use dex2jar to convert this apk into a jar file.
3. Add the jar file to your build path

 

It works again, but now I am totally dependent of this libraryPretty useful if you don’t want to update this library and keep it as it is, develop an MVP, or use the Google Glass offline (not update at all).

 

Why? If there is an update of the Google Glass voice recognition, you might have a conflict. You will need to re-insert your library again in your project, and update your project according to this.

You become totally dependent of the library.

 

To update this library is pretty annoying, and the library contains 59631 methods, which is already 90 %  (+/- ) of the max capacity.

 

The solution?

 

To become totally independent and use a custom Glassvoice , free, and works will all the accent ?

Unfortunately I don’t have any solution for that, but I have one to reduce the size of the library up to 62% !

 

I created a shell script to remove all the parts which is not useful for the voice detection and the speech recogniser in the apk.

Here is the result of the GlassVoice-xe21.0.jar optimised with the script:

 

                   SIZE            NBR_METHODS

Before           7.8MB                59631

After            3.0MB                22541

Optimisation up to  62.2 % of number of methods.

 

Script Available on github.

 

Here is what I removed from the apk :

rm -rf location/
rm -rf com/squareup/
rm -rf com/google/glass/bluetooth/
rm -rf com/google/glass/camera/
rm -rf com/google/glass/connectivity/
rm -rf com/google/glass/html/
rm -rf com/google/glass/location
rm -rf com/google/glass/maps
rm -rf com/google/glass/menu
rm -rf com/google/glass/music
rm -rf com/google/glass/net
rm -rf com/google/glass/phone
rm -rf com/google/glass/sound
rm -rf com/google/glass/timeline
rm -rf com/google/protobuf/
rm -rf com/google/glass/sync
rm -rf com/google/glass/protobuf/
rm -rf com/google/glass/settings/
rm -rf com/google/glass/share
rm -rf com/google/glass/proto
rm -rf com/google/glass/ongoing
rm -rf com/google/glass/mosaic
rm -rf com/google/glass/hidden
rm -rf com/google/glass/deferredcontent/
rm -rf com/google/glass/companion/
rm -rf com/google/glass/boutique/
rm -rf com/google/glass/auth/
rm -rf com/google/glass/async/
rm -rf com/google/android/search/
rm -rf com/google/android/gcm/
rm -rf com/google/android/gms
rm -rf com/google/android/s3
rm -rf com/google/android/gtalkservice/
rm -rf com/google/android/libraries
rm -rf com/google/android/gsf/
rm -rf com/google/geo
rm -rf com/google/caribou/
rm -rf com/google/speech/
rm -rf com/google/wireless
rm -rf com/google/majel/
rm -rf com/google/googlex/
rm -rf com/google/glass/widget/
rm -rf com/google/glass/wifi
rm -rf com/google/bionics
rm -rf com/google/audio
rm -rf com/google/webserver
rm -rf com/google/glass/accessibility
rm -rf com/google/glass/admin
rm -rf com/google/glass/fs
rm -rf com/google/glass/android/security/
rm -rf com/google/glass/android/net/
rm -rf com/google/glass/android/location/
rm -rf com/google/glass/android/hardware/

 

All of these are not needed for the functioning of the voice detection and the speech recogniser.

But I am pretty it is possible to optimise this library more than I do, so feel free to leave a comment to help me to optimise the library more than it is !

With that, You will already save pretty much 62% of method , which should save you from the dalvik limit of methods in your application (which is 65536 methods).

 

Initially the GlassVoice.apk has 59631 methods… So it is a big improvement in your project !

 

This script takes 2 parameters:

Screen Shot 2015-03-27 at 00.29.25

The first parameter is the source jar.

The 2nd parameter is the destination jar.

 

It helps me to update the library and more focus on what I needed to do for the mvp.

I don’t recommend this method if you are developing an application , which is more than a MVP.

If you know another solution for that, please feel free to leave a comment on this tutorial, i will be happy to take a look !

 

On my github you can find the GlassVoice.apk (Xe21) and the script if you want to give a look.

Here is the link on my github.

How to use the GlassVoice : link available here.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>