CLE URDU TTS API REFERENCE

This section presents code snippets for using CLE TTS API with JAVA.

1. The synthesis method of CLE web services takes two mandatory arguments (input text and access token) in JSON format.

                    
String accessToken = "<<your access token>>";
String inputText = PLACE_YOUR_TEXT_HERE;
String JSON_MSG="{ \"text\" : \"" + inputText + "\" , \"token\" : \"" + accessToken + "\", \"voice\" : \"CLE_Naghma1\", \"rate\" : \"" + 2 + "\" , \"volume\" : \"" + 100 + "\"}";

//The voice parameter will always be CLE_Naghma1.
//The rate parameter can take values from -5 to 5.
//The volume parameter can take values from 0 to 200.
                    
                

2. Use JAVA HTTP client for connecting to the web service as shown below. The Apache HttpCore and Apache HttpClient libraries are required which can be downloaded from the Link.

                     
String IP = "api.cle.org.pk";
String postURL = "https://" + IP+ "/v1/synth";
HttpClient   httpClient    = HttpClientBuilder.create().build();
HttpPost     post          = new HttpPost(postURL);
StringEntity postingString = new StringEntity(JSON_MSG,"UTF-8");
post.setEntity(postingString);
post.setHeader("Content-type", "application/json;odata=verbose");
HttpResponse response = httpClient.execute(post);
String JSON_Response=convertStreamToString(response.getEntity().getContent());
            

                    
                

3. The method will return a HTTP response message. The JSON message can be extracted from the HTTP response using the following function. The JSON message contains status and encoded wave file data which can be processed.

                    
private static String convertStreamToString(InputStream is) {

        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
 }