title: How to request IVONA Speech Cloud from an Android app within Android Studio
body: <p>I am trying to implement one of the best text-to-speech (TTS) services out there in an <strong>Android app</strong> which I am working on in <strong>Android Studio</strong>.</p>
  
  <p>The TTS service that I would like to implement in Android is <a href="http://developer.ivona.com/en/speechcloud/index.html" rel="nofollow"><strong>IVONA Speech Cloud</strong></a>, which is <strong>FREE</strong> and gives <strong>access to 53 voices</strong> (at the time being).</p>
  
  <p>I am aware that there is a <strong>SDK for Android</strong>, but the problem is that it <strong>costs 1500 €</strong> for a development license (last I spoke to a sales person from IVONA) which I do not intend to pay.</p>
  
  <p>Also, I am aware that I can simply download the IVONA TTS engine with a limited amount of voices and implement them in my Android application which I did some time ago. This is also free, but I would rather have access to all of the 53 voices and not only 13 (at the time being). Besides, if the user would like all the available voices, that person would have to download them all which can take up a lot of space for some users.</p>
  
  <p>Put it very simply; it is my opinion that it might be the best and easiest way to have an app that sends TTS requests and receives speech (either in terms of speech files or speech URLs) from a web service like IVONA Speech Cloud. Then the user would not have to install the IVONA TTS Speech Engine including several voices.</p>
  
  <p>For the time being, there is an <strong>open-source Java SDK</strong> available that implements the IVONA Speech Cloud. It is not a problem for me to run this in e.g. Eclipse. <strong>The problem is that I can not make this work with my Android app</strong>.</p>
  
  <ul>
  <li><p>Therefore I would like to ask you if it is possible to implement that
  Java SDK in an Android app (in Android Studio)? If yes, how?</p></li>
  <li><p>If not the above is possible, how would an implementation in Android Studio look like using the <a href="http://developer.ivona.com/en/speechcloud/request-signing.html" rel="nofollow">HTTP GET for API requests</a>? You can also go back in the link an see the <strong>API reference</strong>.</p></li>
  </ul>
  
  <p><em>My reputation points (at the time being) only allow me to post 2 links!</em></p>
  
  <p><strong>I would be VERY thankful if someone could describe for me (with code)</strong> how to implement IVONA Speech Cloud in Android Studio from the <strong>Java SDK</strong> or <strong>HTTP GET API requests</strong>. </p>
  
  <hr>
  
  <h1>Update #1</h1>
  
  <p>@BenJakuben suggests that I can convert a Maven dependency into Gradle. Actually I have tried this before without luck. This can be done in two ways; the first is as @BenJakuben described. The second way of doing this is by:</p>
  
  <ol>
  <li>Selecting <strong>File</strong> menu tab in Android Studio</li>
  <li>Choosing <strong>Project Structure</strong></li>
  <li>Selecting <strong>Dependencies</strong> tab</li>
  <li>Clicking the <strong>+</strong> (add) button at the bottom and selecting <strong>1 Library dependency</strong></li>
  <li>Typing in <em>IVONA</em> and hitting the search icon and selecting the first option: <strong>com.ivona:ivona-speechcloud-sdk-java:0.3.0</strong></li>
  <li>Hitting the <strong>OK</strong> button</li>
  </ol>
  
  <p>The sync process reports the following:</p>
  
  <p><strong><code>Gradle build finished with 4 warnings(s) in 2 sec</code></strong></p>
  
  <p>The 4 warnings are as follows:</p>
  
  <blockquote>
    <p><strong>Warning</strong>:Dependency commons-logging:commons-logging:1.1.1 is ignored
    for debug as it may be conflicting with the internal version provided
    by Android.</p>
    
    <p><strong>Warning</strong>:Dependency org.apache.httpcomponents:httpclient:4.2 is ignored
    for debug as it may be conflicting with the internal version provided
    by Android.</p>
    
    <p><strong>Warning</strong>:Dependency commons-logging:commons-logging:1.1.1 is ignored
    for release as it may be conflicting with the internal version
    provided by Android.</p>
    
    <p><strong>Warning</strong>:Dependency org.apache.httpcomponents:httpclient:4.2 is ignored
    for release as it may be conflicting with the internal version
    provided by Android.</p>
  </blockquote>
  
  <p>Afterwards I have tried to copy the <strong>SampleIvonaSpeechCloudGetCreateSpeechURL.java</strong> as well as <strong>IvonaCredentials.properties</strong> file with my <em>accessKey</em> and <em>secretKey</em> I recieved for <strong>FREE</strong> when registering to IVONA Speech Cloud. These 2 files are located in the same package as <strong>MainActivity</strong>.</p>
  
  <p>The <strong>SampleIvonaSpeechCloudGetCreateSpeechURL.java</strong> looks like this:</p>
  
  <pre><code>package IvonaSpeechCloudVoiceList;
  
  import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider;
  import com.ivona.services.tts.IvonaSpeechCloudClient;
  import com.ivona.services.tts.model.ListVoicesRequest;
  import com.ivona.services.tts.model.Voice;
  
  /**
   * Class that generates singed URL for IVONA SpeechCloud ListVoices operation. This URL can be safely passed to
   * client application to final invocation.
   */
  public class SampleIvonaSpeechCloudGetVoiceListURL {
  
      static IvonaSpeechCloudClient speechCloud;
  
      private static void init() {
          speechCloud = new IvonaSpeechCloudClient(
                  new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
          speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
      }
  
      public static void main(String[] args) throws Exception {
  
          init();
  
          ListVoicesRequest allVoicesRequest = new ListVoicesRequest();
          System.out.println("Request for all voices URL: " + speechCloud.getListVoicesUrl(allVoicesRequest));
  
          ListVoicesRequest enUsVoicesRequest = new ListVoicesRequest();
          Voice voice = new Voice();
          voice.setLanguage("en-US");
          enUsVoicesRequest.setVoice(voice);
          System.out.println("Request for en-US voices URL: " + speechCloud.getListVoicesUrl(enUsVoicesRequest));
      }
  }
  </code></pre>
  
  <p>Now, since there are some pure Java syntax a couple of places, I have changed it to the following:</p>
  
  <p><strong>1)</strong> from:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
  </code></pre>
  
  <p><strong>1)</strong> to a constructor with no input parameters:</p>
  
  <pre><code>public SampleIvonaSpeechCloudGetCreateSpeechURL() throws Exception {
  </code></pre>
  
  <p><strong>2)</strong> from:</p>
  
  <pre><code>System.out.println("Request for en-US voices URL: " + speechCloud.getListVoicesUrl(enUsVoicesRequest));
  </code></pre>
  
  <p><strong>2)</strong> to an info message (with the returned URL from IVONA Speech Cloud) in the Log that I can read when the app is executed:</p>
  
  <pre><code>Log.i("TAG","Requested URL: " + speechCloud.getCreateSpeechUrl(createSpeechRequest));
  </code></pre>
  
  <p>Now, in my <strong>MainActivity</strong> I simply declare and instantiate an object from the <strong>SampleIvonaSpeechCloudGetCreateSpeechURL.java</strong> class:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      try {
          SampleIvonaSpeechCloudGetCreateSpeechURL sampleSpeechURL = new SampleIvonaSpeechCloudGetCreateSpeechURL();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>When I try to run the app (on my Android phone) I receive this:</p>
  
  <p><strong><code>Gradle build finished with 1 error(s) and 4 warning(s) in 1 min 25 sec.</code></strong></p>
  
  <blockquote>
    <p><strong>Error</strong>:Execution failed for task ':app:preDexDebug'.
    com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin/java'' finished with non-zero exit value 3</p>
  </blockquote>
  
  <hr>
  
  <h1>Update #2</h1>
  
  <p>In the Gradle file, I added the following lines of codes which took away the 4 warnings addressed in <strong>Update #1</strong>:</p>
  
  <pre><code>configurations {
      all*.exclude group: 'org.apache.httpcomponents'
      all*.exclude group: 'org.apache.commons'
      all*.exclude group: 'commons-logging', module: 'commons-logging'
  }
  </code></pre>
  
  <p>When I want to run my application I still get the erros message. Here it is including all of the information:</p>
  
  <pre><code>Information:Gradle tasks [:app:assembleDebug]
  :app:preBuild UP-TO-DATE
  :app:preDebugBuild UP-TO-DATE
  :app:compileDebugNdk UP-TO-DATE
  :app:checkDebugManifest
  :app:prepareDebugDependencies
  :app:compileDebugAidl UP-TO-DATE
  :app:compileDebugRenderscript UP-TO-DATE
  :app:generateDebugBuildConfig UP-TO-DATE
  :app:generateDebugAssets UP-TO-DATE
  :app:mergeDebugAssets UP-TO-DATE
  :app:generateDebugResValues UP-TO-DATE
  :app:generateDebugResources UP-TO-DATE
  :app:mergeDebugResources UP-TO-DATE
  :app:processDebugManifest UP-TO-DATE
  :app:processDebugResources UP-TO-DATE
  :app:generateDebugSources UP-TO-DATE
  :app:compileDebugJava
  :app:preDexDebug
  UNEXPECTED TOP-LEVEL ERROR:
  java.lang.OutOfMemoryError: GC overhead limit exceeded
      at java.util.BitSet.initWords(BitSet.java:164)
      at java.util.BitSet.&lt;init&gt;(BitSet.java:159)
      at com.android.dx.ssa.SsaBasicBlock.&lt;init&gt;(SsaBasicBlock.java:127)
      at com.android.dx.ssa.SsaMethod.makeExitBlock(SsaMethod.java:200)
      at com.android.dx.ssa.SsaConverter.convertToSsaMethod(SsaConverter.java:58)
      at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:98)
      at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:72)
      at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:297)
      at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
      at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
      at com.android.dx.command.dexer.Main.processClass(Main.java:729)
      at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
      at com.android.dx.command.dexer.Main.access$300(Main.java:83)
      at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
      at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
      at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
      at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
      at com.android.dx.command.dexer.Main.processOne(Main.java:632)
      at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
      at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
      at com.android.dx.command.dexer.Main.run(Main.java:246)
      at com.android.dx.command.dexer.Main.main(Main.java:215)
      at com.android.dx.command.Main.main(Main.java:106)
  </code></pre>
  
  <blockquote>
    <p>Error:Execution failed for task ':app:preDexDebug'.
    com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command
    '/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin/java''
    finished with non-zero exit value 3</p>
  </blockquote>
  
  <pre><code>Information:BUILD FAILED
  Information:Total time: 1 mins 16.967 secs
  Information:1 error
  Information:0 warnings
  Information:See complete output in console
  </code></pre>
  
  <h1>What am I doing wrong?</h1>