Turkish Character Problem

edited October 2015 in How To...

Hi, this question before and I have lived in the android asked in the forum, but could not get any answer. And I've had the problem in java mode. When it comes to my problem, I Turkish character text (); I can print with the function and I'm viewing in the editor. But Turkish characters println (); function can not print to the console. I can not process the characters. (Url operations, etc.).

I'm working on projects, so I can not perform. Java mode and the android mode, how can I solve this problem.

I need your help too. Please share all your ideas. Before I could not get a clear answer to my problem. In fact, I could not ever get. I hope you can help.

Answers

  • edited August 2014

    I want to open this thread a bit more.

    I use a 64-bit operating system Windows 8.1.

    While the system language is English;

    println ("ş"); -------------->? gives the output.

    While the system language is Turkish;

    println ("ş"); ---------------> ş gives the output.

    Changing the system language println (); I was able to print with Turkish characters, but still can not process.   I want to do with the unofficial google text to speech service process.

    import ddf.minim.spi.*;
    import ddf.minim.signals.*;
    import ddf.minim.*;
    import ddf.minim.analysis.*;
    import ddf.minim.ugens.*;
    import ddf.minim.effects.*;
    
    import java.net.*;
    import java.io.*;
    
    AudioPlayer player;
    Minim minim;
    
    boolean successPlay = false;
    
    String textData = "Ş Ğ";
    
    void setup(){
      minim = new Minim(this);
      textToSpeech(textData,"tr");
      playUrlData();
    
      displayWidth=720;
      displayHeight=480;
      size(displayWidth,displayHeight);
    }
    
    void draw(){
      background(0,0,0);
    
      successPlay();
    }
    
    void textToSpeech(String text,String language){
      String urlData = "http://translate.google.com/translate_tts?tl=";
      urlData = urlData + language + "&q=" + text;
      urlData = urlData.replace(" ","%20");
      println(urlData);
    
      try{
        URL url = new URL(urlData);
          try{
            URLConnection connection = url.openConnection();
              connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 1.2.30703)");
              connection.connect();
              InputStream is = connection.getInputStream();
              File f = new File(sketchPath + "/" + text + ".mp3");
              OutputStream out = new FileOutputStream(f);
                byte buf[] = new byte[1024];
                int len;
                while ((len = is.read(buf)) > 0) {
                  out.write(buf, 0, len);
                }
                out.close();
                is.close();
              println("Dosya Yaratıldı: " + text);
          } catch (IOException e) {
            e.printStackTrace();
          }   
      } catch (MalformedURLException e) {
        e.printStackTrace();
      }
    
    }
    
    void playUrlData(){
      if (player != null){
        player.close();
      }
        player = minim.loadFile( textData + ".mp3", 2048);
        player.loop();
        successPlay=true;
    }
    
    void successPlay(){
      if(successPlay==true){
        textSize(24);
        fill(0,255,0);
        text("Dosya Yaratıldı.",30,50);
        fill(0,0,255);
        text("Dosya Oynatılıyor.",30,80);
        text("Dosya Döngüde.",30,200);
        fill(255,255,255);
        text("Dosya Adı:",30,110);
        text("Dosya Uzantısı:",30,140);
        text("Dosya Kök Dizini:",30,170);
        fill(255,0,0);
        text(textData,155,110);
        text(".mp3",210,140);
        text(sketchPath + "/",235,170);
      }
    }
    

    Ş and Ğ to solve my problem I need to hear their voices. Of course, I have not heard in either mode (java and android). I learned this method from ammonp5.

  • edited August 2014 Answer ✓

    Ah, this is much more concrete! Until now, you only had generic complains that perhaps only somebody familiar with your tongue could solve.

    So you are trying to pass a string with international (accented) characters in an URL. Indeed, it just doesn't work. You have to encode each special character to URL escape sequence. Like you do with space characters...

    General note: don't assign values to Processing's variables (displayWidth/Height here), use constants in size(), move size() call to the beginning of setup().

  • Thank you very much for your answer philho I'm grateful. So to solve the problem I needed to encode Turkish characters? I don't know about encode and decode proccess. Do you have a source for processing on this issue?

  • edited August 2014

    Ahh, the after write my last message, I did the following procedure.

    bla.replace("Åž","Ş");
    bla.replace("Äž","Ğ");
    bla.replace("Ç","Ç");
    bla.replace("Ä°","İ");
    bla.replace("Ö","Ö");
    bla.replace("ü","ü");
    bla.replace("ÅŸ","ş");
    bla.replace("ç","ç");
    bla.replace("ı","ı");
    bla.replace("ö","ö");
    bla.replace("ÄŸ","ğ");
    

    And it is work!!! (Java Mode).

    Then I'll try to work on android. Philho Thanks again for your help.

    Also I am sorry for my bad english :)

  • edited August 2014 Answer ✓

    An example to integrate to your sketch:

    void setup()
    {
      doStuff();
    }
    
    void doStuff()
    {
      String language = "tr";
      String text = "Nö Tùrkîsh, büt Frànçâïs will dô the job!";
      String urlData = "http://"+"translate.google.com/translate_tts?tl=";
      urlData = urlData + language + "&q=" + encode(text);
      println(urlData);
    }
    
    String encode(String text)
    {
      try
      {
        return java.net.URLEncoder.encode(text, "UTF-8");
      }
      catch (Exception e)
      {
        return "";
      }
    }
    
  • String objects can be dot-chained: *-:)

    bla.replace("Åž", "Ş")
      .replace("Äž", "Ğ")
        .replace("Ç", "Ç")
          .replace("Ä°", "İ")
            .replace("Ö", "Ö")
              .replace("ü", "ü")
                .replace("ÅŸ", "ş")
                  .replace("ç", "ç")
                    .replace("ı", "ı")
                      .replace("ö", "ö")
                        .replace("ÄŸ", "ğ");
    
Sign In or Register to comment.