| | |
| | | import com.aliyun.teautil.Common; |
| | | import com.aliyun.teautil.models.RuntimeOptions; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.*; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String texttospeech(String textspeech) { |
| | | public String texttospeech(String textspeech, String filePath) { |
| | | this.accessToken(); |
| | | this.process2(textspeech); |
| | | this.process2(textspeech, filePath); |
| | | client.shutdown(); |
| | | return returnResult; |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | private SpeechSynthesizerListener getSynthesizerListener() { |
| | | private SpeechSynthesizerListener getSynthesizerListener(String filePath) { |
| | | SpeechSynthesizerListener listener = null; |
| | | try { |
| | | if (StringUtils.isEmpty(filePath)) { |
| | | filePath = "tts_test.wav"; |
| | | } |
| | | String finalFilePath = filePath; |
| | | listener = new SpeechSynthesizerListener() { |
| | | File f = new File("tts_test.wav"); |
| | | File f = new File(finalFilePath); |
| | | FileOutputStream fout = new FileOutputStream(f); |
| | | private boolean firstRecvBinary = true; |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | public void process2(String text) { |
| | | public void process2(String text, String filePath) { |
| | | SpeechSynthesizer synthesizer = null; |
| | | try { |
| | | //创建实例,建立连接。 |
| | | synthesizer = new SpeechSynthesizer(client, getSynthesizerListener()); |
| | | synthesizer = new SpeechSynthesizer(client, getSynthesizerListener(filePath)); |
| | | synthesizer.setAppKey(appKey); |
| | | //设置返回音频的编码格式 |
| | | synthesizer.setFormat(OutputFormatEnum.WAV); |