├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── manifest.yml ├── pom.xml └── src └── main ├── java └── com │ └── ibm │ └── cloudoe │ └── samples │ └── DemoServlet.java ├── webapp ├── WEB-INF │ └── web.xml ├── css │ ├── style.css │ └── watson-bootstrap-dark.css ├── images │ ├── app.png │ ├── favicon.ico │ └── fork-icon.svg ├── index.jsp └── js │ ├── browser-detect.js │ ├── constants.js │ ├── demo.js │ └── jquery-1.11.1.min.js └── wlp └── server.xml /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | .DS_Store 3 | /target 4 | *~ 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Questions 2 | 3 | If you are having difficulties running the app or have a question about the service, please ask a question on [dW Answers](https://developer.ibm.com/answers/questions/ask/?topics=watson) or [Stack Overflow](http://stackoverflow.com/questions/ask?tags=ibm-watson). 4 | 5 | # Issues 6 | 7 | If you encounter an issue with this sample app, you are welcome to submit a [bug report](https://github.com/watson-developer-cloud/text-to-speech-java/issues). Before that, please search for similar issues. It's possible somebody has encountered this issue already. 8 | 9 | # Pull Requests 10 | 11 | If you want to contribute to the repository, here's a quick guide: 12 | 13 | 1. Fork the repo 14 | 1. develop your code changes 15 | 1. Commit your changes 16 | 1. Push to your fork and submit a pull request -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | This product includes software originally developed by IBM Corporation 2 | Copyright 2015 IBM Corp. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Text to Speech Java Starter Application 2 | 3 | ## DEPRECATED: this repo is no longer actively maintained. It can still be used as reference, but may contain outdated or unpatched code. 4 | 5 | The IBM Watson [Text to Speech][service_url] service is designed for streaming, low latency, synthesis of audio from text. It is the inverse of the automatic speech recognition. The TTS service can be accessed via a REST interface or directly via TCP. 6 | 7 | Give it a try! Click the button below to fork into IBM DevOps Services and deploy your own copy of this application on Bluemix. 8 | 9 | [![Deploy to Bluemix](https://bluemix.net/deploy/button.png)](https://bluemix.net/deploy) 10 | 11 | ## Building the application 12 | 13 | Use [Apache Maven](https://maven.apache.org/) to build the application. 14 | 15 | ```sh 16 | $ mvn install 17 | ``` 18 | 19 | ## Deploying to Bluemix 20 | 21 | 1. Create a Bluemix Account 22 | 23 | [Sign up][sign_up] in Bluemix, or use an existing account. Watson Services in Beta are free to use. 24 | 25 | 2. Download and install the [Cloud-foundry CLI][cloud_foundry] tool 26 | 27 | 3. Connect to Bluemix in the command line tool. 28 | ```sh 29 | $ cf login -a https://api.ng.bluemix.net 30 | ``` 31 | 32 | 4. Create the `Text to Speech` service in Bluemix. 33 | ```sh 34 | $ cf create-service text_to_speech standard text-to-speech-service 35 | ``` 36 | 37 | 5. [Build the application](#building-the-application). 38 | 39 | 6. Deploy the application. Ensure the `` is something unique. 40 | 41 | ```sh 42 | $ cf push -p target/text-to-speech-1.0-SNAPSHOT.war 43 | ``` 44 | 45 | Once deployed, the application will be available at `http://.mybluemix.net`. 46 | 47 | ## Running locally 48 | 49 | The application uses [WebSphere Liberty](https://developer.ibm.com/wasdev/websphere-liberty/) as its server. Liberty provides the [bluemixUtility](http://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/rwlp_blmx_utility.html) command line client that makes it easy for applications to use certain Bluemix services. 50 | 51 | 1. [Build the application](#building-the-application). 52 | 53 | 2. Initialize Liberty server for the application. Maven will automatically download and install WebSphere Liberty. 54 | 55 | ```sh 56 | $ mvn liberty:create-server 57 | ``` 58 | 59 | 3. Log in to Bluemix and create `Text to Speech` service instance as described in [Deploying to Bluemix](#deploying-to-bluemix) steps 1-4. 60 | 61 | 4. Use `bluemixUtility` to import configuration for the `Text to Speech` service. 62 | 63 | ```sh 64 | $ ./target/wlp/bin/bluemixUtility import text-to-speech-service 65 | ``` 66 | 67 | 5. Bind the imported configuration to Liberty server. 68 | 69 | ```sh 70 | $ ./target/wlp/bin/bluemixUtility bind defaultServer text-to-speech-service 71 | ``` 72 | 73 | 6. Start the application. 74 | 75 | ```sh 76 | $ mvn liberty:run-server 77 | ``` 78 | 79 | Once started, the application will be available at [http://localhost:9080/text2speech](http://localhost:9080/text2speech). 80 | 81 | ## Troubleshooting 82 | 83 | To troubleshoot your Bluemix application, the most useful source of 84 | information is the log files. To see them, run the following command: 85 | 86 | ```sh 87 | $ cf logs --recent 88 | ``` 89 | 90 | ## License 91 | 92 | This sample code is licensed under Apache 2.0. Full license text is available in [LICENSE](LICENSE). 93 | The sample uses jQuery which is licensed under MIT 94 | 95 | ## Contributing 96 | 97 | See [CONTRIBUTING](CONTRIBUTING.md). 98 | 99 | ## Open Source @ IBM 100 | 101 | Find more open source projects on the 102 | [IBM Github Page](http://ibm.github.io/). 103 | 104 | [service_url]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/text-to-speech.html 105 | [cloud_foundry]: https://github.com/cloudfoundry/cli 106 | [sign_up]: https://apps.admin.ibmcloud.com/manage/trial/bluemix.html?cm_mmc=WatsonDeveloperCloud-_-LandingSiteGetStarted-_-x-_-CreateAnAccountOnBluemixCLI 107 | [liberty]: https://developer.ibm.com/wasdev/downloads/ 108 | [liberty_mac]: http://www.stormacq.com/how-to-install-websphere-8-5-liberty-profile-on-mac/ 109 | [ant]: http://ant.apache.org/bindownload.cgi 110 | -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | declared-services: 3 | text-to-speech-service: 4 | label: text_to_speech 5 | plan: standard 6 | applications: 7 | - services: 8 | - text-to-speech-service 9 | name: text-to-speech-java 10 | path: target/text-to-speech-1.0-SNAPSHOT.war 11 | memory: 512M 12 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | com.ibm.watson.sample 7 | text-to-speech 8 | 1.0-SNAPSHOT 9 | war 10 | 11 | Watson Text-To-Speech Sample 12 | 13 | 14 | UTF-8 15 | UTF-8 16 | 17 | 18 | 19 | 20 | javax.servlet 21 | javax.servlet-api 22 | 3.1.0 23 | provided 24 | 25 | 26 | com.ibm.watson.developer_cloud 27 | java-sdk 28 | 2.9.0 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.apache.maven.plugins 37 | maven-compiler-plugin 38 | 3.5.1 39 | 40 | 1.7 41 | 1.7 42 | 43 | 44 | 45 | net.wasdev.wlp.maven.plugins 46 | liberty-maven-plugin 47 | 1.1 48 | 49 | 50 | 51 | 52 | 53 | net.wasdev.wlp.maven.plugins 54 | liberty-maven-plugin 55 | 56 | src/main/wlp/server.xml 57 | 58 | ${project.build.finalName} 59 | 60 | 61 | com.ibm.websphere.appserver.runtime 62 | wlp-webProfile7 63 | 8.5.5.9 64 | zip 65 | 66 | ${project.build.directory} 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/main/java/com/ibm/cloudoe/samples/DemoServlet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2016 IBM Corp. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ibm.cloudoe.samples; 17 | 18 | import java.io.Closeable; 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.io.OutputStream; 22 | import java.util.logging.Level; 23 | import java.util.logging.Logger; 24 | 25 | import javax.servlet.ServletException; 26 | import javax.servlet.http.HttpServlet; 27 | import javax.servlet.http.HttpServletRequest; 28 | import javax.servlet.http.HttpServletResponse; 29 | 30 | import com.ibm.watson.developer_cloud.text_to_speech.v1.TextToSpeech; 31 | import com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice; 32 | 33 | public class DemoServlet extends HttpServlet { 34 | 35 | private static Logger logger = Logger.getLogger(DemoServlet.class.getName()); 36 | private static final long serialVersionUID = 1L; 37 | 38 | /** 39 | * Forward the request to the index.jsp file if no parameters are specified. 40 | * 41 | * Invoke GET request to the Watson service otherwise 42 | * 43 | * @param req the req 44 | * @param resp the resp 45 | * @throws ServletException the servlet exception 46 | * @throws IOException Signals that an I/O exception has occurred. 47 | */ 48 | @Override 49 | protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { 50 | if (req.getParameter("text") == null || req.getParameter("voice") == null) { 51 | req.getRequestDispatcher("/index.jsp").forward(req, resp); 52 | } else { 53 | boolean download = "true".equalsIgnoreCase(req.getParameter("download")); 54 | 55 | InputStream in = null; 56 | OutputStream out = null; 57 | try { 58 | TextToSpeech textService = new TextToSpeech(); 59 | String voice = req.getParameter("voice"); 60 | String text = req.getParameter("text"); 61 | String format = "audio/ogg; codecs=opus"; 62 | in = textService.synthesize(text, new Voice(voice, null, null), format); 63 | 64 | if (download) { 65 | resp.setHeader("content-disposition", 66 | "attachment; filename=transcript.ogg"); 67 | } 68 | 69 | out = resp.getOutputStream(); 70 | byte[] buffer = new byte[2048]; 71 | int read; 72 | while ((read = in.read(buffer)) != -1) { 73 | out.write(buffer, 0, read); 74 | } 75 | } catch (Exception e) { 76 | // Log something and return an error message 77 | logger.log(Level.SEVERE, "got error: " + e.getMessage(), e); 78 | resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); 79 | } finally { 80 | close(in); 81 | close(out); 82 | } 83 | } 84 | } 85 | 86 | private void close(Closeable closeable) { 87 | if (closeable != null) { 88 | try { 89 | closeable.close(); 90 | } catch (IOException e) { 91 | // ignore 92 | } 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Java Starter Application 8 | 9 | demo 10 | 11 | 12 | Application Servlet 13 | com.ibm.cloudoe.samples.DemoServlet 14 | 1 15 | 16 | 17 | Application Servlet 18 | /demo 19 | 20 | -------------------------------------------------------------------------------- /src/main/webapp/css/style.css: -------------------------------------------------------------------------------- 1 | .no-scroll { 2 | overflow: hidden; 3 | } 4 | 5 | .img-container img { 6 | width: 100%; 7 | height: auto; 8 | } 9 | 10 | .top-nav { 11 | background-color: #404041; 12 | padding-top: 15px; 13 | padding-bottom: 15px; 14 | } 15 | .top-nav a { 16 | font-size: 14px; 17 | font-weight: 300; 18 | text-decoration: underline; 19 | color: white; 20 | } 21 | .top-nav a:hover { 22 | color: #E0E0E0; 23 | } 24 | 25 | .top-nav .right { 26 | float: right; 27 | margin-right: 20px; 28 | } 29 | .top-nav .left { 30 | float: left; 31 | } 32 | .top-nav .fork:before { 33 | content: " "; 34 | background: url("../images/fork-icon.svg") no-repeat; 35 | height: 16px; 36 | width: 16px; 37 | vertical-align: text-bottom; 38 | display: inline-block; 39 | margin-right: 3px; 40 | } 41 | .header { 42 | padding-bottom:0px; 43 | margin-bottom: 0px; 44 | position: relative; 45 | } 46 | .header h2 { 47 | font-weight: 400; 48 | } 49 | .header h3 { 50 | color: #00b2ef; 51 | font-weight: 400; 52 | } 53 | .avatar { 54 | padding-right: 0px; 55 | } 56 | .avatar img { 57 | margin-top: 9px; 58 | } 59 | .header a { 60 | font-size: 14px; 61 | font-weight: 300; 62 | text-decoration: underline; 63 | color: #404041; 64 | display: block; 65 | margin-left: 20px; 66 | margin-bottom: 3px; 67 | } 68 | .header a:hover { 69 | color: #777677; 70 | } 71 | 72 | .errorMsg { 73 | font-weight:bold; 74 | color: #FF5050; 75 | } 76 | .pause { 77 | display: none; 78 | } 79 | 80 | .ie-speak { 81 | position: relative; 82 | } 83 | .speak-button:disabled { 84 | opacity: 0.2; 85 | } 86 | .ie-speak .arrow-box { 87 | position: absolute; 88 | width: 220px; 89 | height: 107px; 90 | padding: 15px; 91 | background-color: #00b2ef; 92 | color: white; 93 | bottom: 100%; 94 | left: -9999px; 95 | right: -9999px; 96 | margin: auto; 97 | visibility: hidden; 98 | opacity: 0; 99 | -webkit-transition: 0.2s; 100 | -moz-transition: 0.2s; 101 | -ms-transition: 0.2s; 102 | -o-transition: 0.2s; 103 | transition: 0.2s; 104 | display: none; 105 | } 106 | .ie-speak .arrow-box:after { 107 | content: ' '; 108 | border: 10px solid transparent; 109 | border-top: 10px solid #00b2ef; 110 | position: absolute; 111 | top: 100%; 112 | left: 50%; 113 | margin-left: -10px; 114 | } 115 | .ie-speak:hover .arrow-box { 116 | -webkit-transform: translateY(-20px); 117 | -moz-transform: translateY(-20px); 118 | -ms-transform: translateY(-20px); 119 | -o-transform: translateY(-20px); 120 | transform: translateY(-20px); 121 | visibility: visible; 122 | opacity: 1; 123 | } 124 | -------------------------------------------------------------------------------- /src/main/webapp/images/app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watson-developer-cloud/text-to-speech-java/3cd1602287e022cbb783f17dd30834413ee06f44/src/main/webapp/images/app.png -------------------------------------------------------------------------------- /src/main/webapp/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watson-developer-cloud/text-to-speech-java/3cd1602287e022cbb783f17dd30834413ee06f44/src/main/webapp/images/favicon.ico -------------------------------------------------------------------------------- /src/main/webapp/images/fork-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 3 | 4 | 5 | 6 | Text to Speech 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |
19 |
20 |
21 | 28 |
29 |
30 |
31 | 32 |
33 |
34 |

Text to Speech Java Starter Application

35 |

The Text to Speech service uses IBM's speech synthesis capabilities to convert English or Spanish text to an audio signal. The audio is streamed back to the client with minimal delay. The service can be accessed via a REST interface.

36 |
37 |
38 |

Keep Exploring:

DocumentationAPI Details 39 |
40 |
41 |
42 |
43 |
44 |
45 |

Try the service

46 |
47 |
48 |
49 |
50 |
51 | 52 | The text language must match the selected voice language: 53 | Mixing language (English text with a Spanish voice) does not produce valid results. 54 |
55 |
56 |
57 | 58 |
59 | 61 |
62 |
63 |
64 |
65 | 66 |
67 |
68 |
69 | 70 |
71 |

This browser cannot play the ogg audio format. Use Chrome or Firefox to play audio.

72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |

Output

81 |
82 |
83 | 90 | 97 |
98 |
99 |
100 |
101 |
102 |
Audio output only plays on browsers supporting 103 | ogg audio format, including recent versions of Chrome and Firefox. 104 |
105 |
106 |
107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /src/main/webapp/js/browser-detect.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 IBM Corp. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 'use strict'; 17 | /* 18 | This code is made by James Zhang. 19 | This is a very basic browser sniffer. 20 | */ 21 | 22 | (function() { 23 | 24 | var userAgent = window.navigator.userAgent; 25 | // Browser User Agent Strings 26 | var ie = 'MSIE'; 27 | var ie9 = 'MSIE 9.0'; 28 | var ie10 = 'MSIE 10.0'; 29 | var chrome = 'Chrome'; 30 | var firefox = 'Firefox/'; 31 | var safari = 'Safari'; 32 | // OS User Agent Strings 33 | var windows = 'Windows'; 34 | var mac = 'Macintosh'; 35 | var linux = 'Linux'; 36 | 37 | // class names 38 | var ie_class = 'ie'; 39 | var ie9_class = 'ie9'; 40 | var ie10_class = 'ie10'; 41 | var ie11_class = 'ie11'; 42 | var chrome_class = 'chrome'; 43 | var firefox_class = 'firefox'; 44 | var safari_class = 'safari'; 45 | var windows_class = 'windows'; 46 | var mac_class = 'mac'; 47 | var linux_class = 'linux'; 48 | 49 | // All matching classes will be appended to classes 50 | var classes = ''; 51 | 52 | // using UserAgent, checking to see which match 53 | if (userAgent.indexOf(ie) > -1) { 54 | classes += ie_class + ' '; 55 | } 56 | if (userAgent.indexOf(ie9) > -1) { 57 | classes += ie9_class + ' '; 58 | } 59 | if (userAgent.indexOf(ie10) > -1) { 60 | classes += ie10_class + ' '; 61 | } 62 | if (!!navigator.userAgent.match(/Trident.*rv\:11\./)) { 63 | classes += ie_class + ' ' + ie11_class + ' '; 64 | } 65 | if (userAgent.indexOf(safari) > -1 && userAgent.indexOf(chrome) === -1) { 66 | classes += safari_class + ' '; 67 | } 68 | if (userAgent.indexOf(chrome) > -1) { 69 | classes += chrome_class + ' '; 70 | } 71 | if (userAgent.indexOf(firefox) > -1) { 72 | classes += firefox_class + ' '; 73 | } 74 | if (userAgent.indexOf(windows) > -1) { 75 | classes += windows_class + ' '; 76 | } 77 | if (userAgent.indexOf(mac) > -1) { 78 | classes += mac_class + ' '; 79 | } 80 | if (userAgent.indexOf(linux) > -1) { 81 | classes += linux_class + ' '; 82 | } 83 | 84 | // trimming off additional space 85 | classes = classes.slice(0, -1); 86 | 87 | document.addEventListener('DOMContentLoaded', function() { 88 | // adding class names to body tag 89 | document.body.className += classes; 90 | }); 91 | 92 | // exposing browser information globally 93 | window.browserInfo = classes; 94 | 95 | return classes; 96 | 97 | })(); -------------------------------------------------------------------------------- /src/main/webapp/js/constants.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2015 IBM Corp. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 'use strict'; 18 | 19 | // Sample text values 20 | var SAMPLE_TEXT = { 21 | 'es-ES': "Consciente de su patrieso espiritual y moral, la Unión está fundada sobre los valores indivisibles y universales de la dignidad humana, la libertad, la igualdad y la solidaridad, y se basa en los principios de la democracia y el Estado de Derecho. Al instituir la ciudadanía de la Unión y crear un espacio de libertad, seguridad y justicia, sitúa a la persona en el centro de su actuación.", 22 | 'fr-FR': "Consciente de son patrimoine spirituel et moral, l'Union se fonde sur les valeurs indivisibles et universelles de dignité humaine, de liberté, d'égalité et de solidarité; elle repose sur le principe de la démocratie et le principe de l'État de droit. Elle place la personne au coeur de son action en instituant la citoyenneté de l'Union et en créant un espace de liberté, de sécurité et de justice.", 23 | 'en-US': "Conscious of its spiritual and moral heritage, the Union is founded on the indivisible, universal values of human dignity, freedom, equality and solidarity; it is based on the principles of democracy and the rule of law. It places the individual at the heart of its activities, by establishing the citizenship of the Union and by creating an area of freedom, security and justice.", 24 | 'de-DE': "In dem Bewusstsein ihres geistig-religiösen und sittlichen Erbes gründet sich die Union auf die unteilbaren und universellen Werte der Würde des Menschen, der Freiheit, der Gleichheit und der Solidarität. Sie beruht auf den Grundsätzen der Demokratie und der Rechtsstaatlichkeit. Sie stellt den Menschen in den Mittelpunkt ihres Handelns, indem sie die Unionsbürgerschaft und einen Raum der Freiheit, der Sicherheit und des Rechts begründet.", 25 | 'it-IT': "Consapevole del suo patrimonio spirituale e morale, l'Unione si fonda sui valori indivisibili e universali della dignità umana, della libertà, dell'uguaglianza e della solidarietà; essa si basa sul principio della democrazia e sul principio dello Stato di diritto. Pone la persona al centro della sua azione istituendo la cittadinanza dell'Unione e creando uno spazio di libertà, sicurezza e giustizia." 26 | }; 27 | 28 | SAMPLE_TEXT['es-US'] = SAMPLE_TEXT['es-ES']; 29 | 30 | var VOICES = { 31 | 'en-US_AllisonVoice' : 'English (en-US): Allison (female)', 32 | 'en-US_LisaVoice' : 'English (en-US): Lisa (female)', 33 | 'en-US_MichaelVoice' : 'English (en-US): Michael (male)', 34 | 'fr-FR_ReneeVoice' : 'French (fr-FR): Renee (female)', 35 | 'de-DE_BirgitVoice' : 'German (de-DE): Birgit (female)', 36 | 'de-DE_DieterVoice' : 'German (de-DE): Dieter (male)', 37 | 'it-IT_FrancescaVoice': 'Italian (it-IT): Francesca (female)', 38 | 'es-ES_LauraVoice' : 'Spanish (es-US): Laura (female)', 39 | 'es-US_SofiaVoice' : 'Spanish (en-US): Sofia (female)', 40 | 'es-ES_EnriqueVoice' : 'Spanish (es-ES): Enrique (male)' 41 | }; -------------------------------------------------------------------------------- /src/main/webapp/js/demo.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 IBM Corp. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /*global $, VOICES, SAMPLE_TEXT */ 18 | 19 | 'use strict'; 20 | 21 | $(document).ready(function() { 22 | var audio = $('.audio').get(0), 23 | textArea = $('#textArea'); 24 | 25 | Object.keys(VOICES).forEach(function(key) { 26 | $('