Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void textToSpeech(ActionEvent actionEvent) throws Exception {
- VoiceProvider tts = new VoiceProvider("2130d5966a01404e94526dd3ccdb4062");
- VoiceParameters params = new VoiceParameters(textField.getText(), Languages.English_UnitedStates);
- params.setCodec(AudioCodec.WAV);
- params.setFormat(AudioFormat.Format_44KHZ.AF_44khz_16bit_stereo);
- params.setBase64(false);
- params.setSSML(false);
- params.setRate(0);
- byte[] voice = tts.speech(params);
- FileOutputStream fos = new FileOutputStream("src\\voice.mp3");
- fos.write(voice, 0, voice.length);
- fos.flush();
- fos.close();
- //play mp3 file
- try {
- AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(this.getClass().getResource("voice.mp3"));
- Clip clip = AudioSystem.getClip();
- clip.open(audioInputStream);
- clip.start();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment