Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

66
LINES

< > BotCompany Repo | #1001260 // Speech test

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (279L/3K/9K).

!747

m {
  //static S text = "This is William";
  //static S voice = "William";
  
  static S text = "Jawohl mein Herr";
  static S voice = "Leopold";
  
  static S format = "mp3"; // "ogg"
  
  p {
    S post = "<speakExtended key='p86ffzyal3tvgqfr'><voice>" + htmlencode(voice) + "</voice><text>" + htmlencode(text) + "</text><audioFormat>" + format + "</audioFormat>\n" +
"</speakExtended>";

    S url = "https://www.cereproc.com/livedemo.php";
    URL _url = new URL(url);
    URLConnection conn = _url.openConnection();
    conn.setRequestProperty("Content-Type", "text/plain;charset=UTF-8");
    conn.setRequestProperty("Accept", "*/*");
    conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
    conn.setRequestProperty("Accept-Language", "en-US,en;q=0.8,de;q=0.6");
    conn.setRequestProperty("Cookie", "has_js=1; Drupal.visitor.liveDemo=p86ffzyal3tvgqfr; _ga=GA1.2.1406621623.1444122980; _gat=1");
    conn.setRequestProperty("Origin", "https://www.cereproc.com");
    conn.setRequestProperty("Referer", "https://www.cereproc.com/");
    conn.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36");
    
    conn.setDoOutput(true);
    
    OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
    writer.write(post);
    writer.flush();
    
    S encoding = conn.getContentEncoding();
    print("Encoding: " + encoding);
    
    S contentType = conn.getContentType();
    print("Content type: " + contentType);
  
    byte[] response = loadBinaryPage(conn);
    print("Bytes read: " + response.length);
    
    if ("gzip".equals(encoding))
      response = gunzipBinaryData(response);
      
    print("Bytes unpacked: " + response.length);
    S s = new String(response, "UTF-8");
    print(s);
    
    S oggUrl = null;
    L<S> tok = htmlcoarsetok(s);
    for (int i = 1; i < tok.size(); i += 2)
      if (isTag(tok.get(i), "url")) {
        oggUrl = tok.get(i+1);
        break;
      }
    if (oggUrl == null) print("No sound URL found");
    
    byte[] ogg = loadBinaryPage(oggUrl);
    print("Sound bytes: " + ogg.length);
    
    File outFile = new File(programDir(programID), "bla." + format);
    saveBinaryFile(outFile, ogg);
    print("Saved: " + outFile.getAbsolutePath());
  }
}

Author comment

Yeah I will buy the app :)

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001260
Snippet name: Speech test
Eternal ID of this version: #1001260/1
Text MD5: ca8e71bc8cf53fb06efa820b93dd2f54
Transpilation MD5: f1b1e1b9c7f1e359121859d1466571e7
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-06 12:14:59
Source code size: 2421 bytes / 66 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 613 / 652
Referenced in: #1001264 - Data file /home/stefan/JavaX-Data/#1001260/bla.ogg from teubizvjbppd
#1001268 - Desktop: Speech test with playing
#3000189 - Answer for stefanreich(>> t bla)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)