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

51
LINES

< > BotCompany Repo | #1009233 // CereProc Cloud Test [WORKS]

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

Uses 74K of libraries. Click here for Pure Java version (1795L/12K/42K).

1  
!7
2  
3  
p {
4  
  // Try coughing
5  
  //S text = [[<spurt audio="g0001_004">cough</spurt> I can now cough]];
6  
  
7  
  S text = [[<spurt audio="g0001_028">cough</spurt>]];
8  
9  
  //S text = [[Today, <voice emotion='happy'>the sun is shining.</voice>]];
10  
  
11  
  //S text = [[When people leave a tip they want to know it will
12  
  //<voice emotion='cross'> not be used</voice> to make up the minimum wage.]];
13  
  
14  
  File credentialsFile = newFile(javaxSecretDir(), "cereproc.txt");
15  
  L<S> secret = tlft(credentialsFile);
16  
  assertEquals("Please give me " + f2s(credentialsFile), 2, l(secret));
17  
  
18  
  String xml = "<?xml version='1.0'?><speakSimple>"
19  
      +"<accountID>" + first(secret) + "</accountID>"
20  
      +"<password>" + second(secret) + "</password>"
21  
      +"<voice>Jess</voice>"
22  
      +"<text>" + text + "</text></speakSimple>";
23  
      
24  
  URL u = new URL("https://cerevoice.com/rest/rest_1_1.php");
25  
  URLConnection uc = openConnection(u);
26  
  HttpURLConnection connection = (HttpURLConnection) uc;
27  
  connection.setDoOutput(true);
28  
  connection.setDoInput(true);
29  
  connection.setRequestMethod("POST");
30  
  connection.setRequestProperty("Content-Type","text/xml; charset=utf-8");
31  
  connection.setRequestProperty("Content-Length", String.valueOf(xml));
32  
  OutputStream out = connection.getOutputStream();
33  
  Writer wout = new OutputStreamWriter(out);
34  
  wout.write(xml);  
35  
  wout.flush();
36  
  wout.close();
37  
  S result = utf8streamToString(connection.getInputStream());
38  
  printIndent(result);
39  
  /* 
40  
     Using your favourite Java XML Parser,
41  
     parse the XML output, check that resultCode is
42  
     equal to 1 and act accordingly 
43  
  */
44  
  assertEquals("Voice Synthesis Result", "1", xml_contentsOfTag(result, "resultCode"));
45  
  S fileUrl = xml_contentsOfTag(result, "fileUrl");
46  
  print("URL: " + fileUrl);
47  
  byte[] data = loadBinaryPage(fileUrl);
48  
  print("Got " + l(data) + " bytes");
49  
  saveBinaryProgramFile("jess.ogg", data);
50  
  playOgg(byteArrayInputStream(data));
51  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1009233
Snippet name: CereProc Cloud Test [WORKS]
Eternal ID of this version: #1009233/23
Text MD5: 2a2004aeb6348ae0338b4ab795645b55
Transpilation MD5: 6b37ed250db0283d95fb0c22da8d0230
Author: stefan
Category: javax / tts
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-25 17:57:53
Source code size: 1979 bytes / 51 lines
Pitched / IR pitched: No / No
Views / Downloads: 541 / 627
Version history: 22 change(s)
Referenced in: [show references]