Google TTS, Help me

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;


AudioPlayer player;
Minim minim;
String MP3_Link = "";

void setup()
{ 

  MP3_Link = doStuff();
  println(MP3_Link);
  player = minim.loadFile( MP3_Link + ".mp3", 2048);
  player.loop();
}

String doStuff()
{
  String language = "ko-KR";
  String text = "Hello";
  String urlData = "http://"+"translate.google.com/translate_tts?tl=";
  urlData = urlData + language + "&q=" + encode(text);
  println(urlData);
  return urlData;
}

String encode(String text)
{
  try
  {
    return java.net.URLEncoder.encode(text, "UTF-8");
  }
  catch (Exception e)
  {
    return "";
  }
}

Good morning. nice to meet you.

I found the source code in the forum, but it does not work.

image

Is there a way to solve this? (I want to work in Android mode.)

Tagged:

Answers

  • edited October 2017

    @Gwak===

    minim does not work with android so you get a NPE: use mediaPlayer + setDataSource(yoururl)

  • edited October 2017
    import android.media.MediaPlayer;
    import  android.content.res.Resources;
    import android.content.res.AssetFileDescriptor;
    import android.content.res.AssetManager;
    import android.content.Context;
    import android.app.Activity;
    
    MediaPlayer snd = new MediaPlayer();
    //AssetManager assets = this.getAssets();
    AssetFileDescriptor fd;
    Context context;
    Button bPlay;
    Activity act;
    
    void setup()
    {
      colorMode(HSB);
      size(800, 800);
      act = this.getActivity();
      context = act.getApplicationContext();
      try {
    
        fd = context.getAssets().openFd("https:"
            + "//translate.google.com/translate_tts"
            + "?ie=UTF-8&tl=ko-KR&client=tw-ob&q=Hello");
        snd.setDataSource(fd.getFileDescriptor(),fd.getStartOffset(), fd.getLength());
      }
      catch (IllegalArgumentException e) {
        e.printStackTrace();
      }
      catch (IllegalStateException e) {
        e.printStackTrace();
      } 
      catch (IOException e) {
        e.printStackTrace();
      }
     }
    

    Dear akenaton,

    1. Is the url wrong?

    2. Or is it(source code) wrong?

  • edited October 2017

    @GWAK===

    code is wrong: you are looking for an asset and not for an url. the url seems to work though i don't understand why you use "+". you never prepare and start the player.

  • (mod: the +s are fine, just string concat - i added them when i broke up the url to stop the forum formatter adding erroneous href markup)

  • @koogs===

    ah! ok....but the code is wrong!

Sign In or Register to comment.