| | |
| | | import com.alibaba.nls.client.protocol.tts.SpeechSynthesizer; |
| | | import com.alibaba.nls.client.protocol.tts.SpeechSynthesizerListener; |
| | | import com.alibaba.nls.client.protocol.tts.SpeechSynthesizerResponse; |
| | | import com.aliyun.dysmsapi20170525.Client; |
| | | import com.aliyun.dysmsapi20170525.models.*; |
| | | import com.aliyun.tea.TeaException; |
| | | import com.aliyun.teaopenapi.models.Config; |
| | | 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.*; |
| | | import com.smartor.service.IBaseSmsaccountService; |
| | | import com.smartor.service.ISvyLibTitleService; |
| | | import com.smartor.service.PersonVoiceService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jsoup.Jsoup; |
| | |
| | | import java.io.*; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.file.Files; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 短信账号Service业务层处理 |
| | |
| | | private String accessKeySecret; |
| | | |
| | | @Autowired |
| | | private SvyLibTitleMapper svyLibTitleMapper; |
| | | private SvyLibTemplateWjxMapper svyLibTitleMapper; |
| | | |
| | | @Autowired |
| | | private SvyLibTopicMapper svyLibTopicMapper; |
| | | private SvyLibTemplateScriptWjxMapper svyLibTopicMapper; |
| | | |
| | | @Autowired |
| | | private SvyLibTopicdirectionMapper svyLibTopicdirectionMapper; |
| | | |
| | | @Autowired |
| | | private SvyLibTopicoptionMapper svyLibTopicoptionMapper; |
| | | private SvyLibTemplateTargetoptionWjxMapper svyLibTopicoptionMapper; |
| | | // |
| | | // @Autowired |
| | | // private ISvyLibTitleService svyLibTitleService; |
| | |
| | | } |
| | | |
| | | @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; |
| | | } |
| | |
| | | } |
| | | |
| | | public String explainHTML2() throws IOException { |
| | | |
| | | String folderPath = "E:\\pc2"; |
| | | // 获取文件夹下的所有文件 |
| | | File[] files = new File(folderPath).listFiles(); |
| | |
| | | String fileContent = new String(Files.readAllBytes(file.toPath())); |
| | | |
| | | Document parse = Jsoup.parse(fileContent); |
| | | Element body = parse.body(); |
| | | Elements elementsByClass3 = body.getElementsByClass("topic__type-des"); |
| | | String desc = elementsByClass3.text(); |
| | | |
| | | //保存title |
| | | String title = parse.title(); |
| | | SvyLibTitle svyLibTitle = new SvyLibTitle(); |
| | | SvyLibTemplateWjx svyLibTitle = new SvyLibTemplateWjx(); |
| | | // svyLibTitle.setCategoryid(System.currentTimeMillis()); |
| | | svyLibTitle.setSvyname(title); |
| | | svyLibTitle.setDescription(desc); |
| | | svyLibTitle.setDelFlag("0"); |
| | | svyLibTitle.setIsupload(0L); |
| | | svyLibTitleMapper.insertSvyLibTitle(svyLibTitle); |
| | | |
| | | Element body = parse.body(); |
| | | svyLibTitleMapper.insertSvyLibTemplateWjx(svyLibTitle); |
| | | |
| | | |
| | | Elements elementsByClass = body.getElementsByClass("topic__type-body"); |
| | | Elements children = elementsByClass.get(0).children(); |
| | | for (Element element : children) { |
| | |
| | | String legend = element.getElementsByTag("legend").text(); |
| | | System.out.println("题目: " + legend); |
| | | //将题目保存到表中 |
| | | SvyLibTopic svyLibTopic = new SvyLibTopic(); |
| | | SvyLibTemplateScriptWjx svyLibTopic = new SvyLibTemplateScriptWjx(); |
| | | svyLibTopic.setSvyid(svyLibTitle.getSvyid()); |
| | | |
| | | //判断该题目下是否有选项 |
| | |
| | | if (spans.size() != 0) { |
| | | Elements radio__type = spans.get(0).getElementsByClass("radio__type"); |
| | | if (radio__type.size() != 0) { |
| | | svyLibTopic.setTopictype("1"); |
| | | svyLibTopic.setScriptType("1"); |
| | | } else { |
| | | Elements checkbox__type = spans.get(0).getElementsByClass("checkbox__type"); |
| | | if (checkbox__type.size() != 0) { |
| | | svyLibTopic.setTopictype("2"); |
| | | svyLibTopic.setScriptType("2"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | svyLibTopic.setTopiccode(IdUtils.simpleUUID()); |
| | | svyLibTopic.setTopic(legend); |
| | | svyLibTopic.setSeqno(IdUtils.simpleUUID()); |
| | | svyLibTopic.setScriptContent(legend); |
| | | svyLibTopic.setDelFlag("0"); |
| | | svyLibTopic.setIsupload(0L); |
| | | svyLibTopic.setOrgid(fileName); |
| | | try { |
| | | svyLibTopicMapper.insertSvyLibTopic(svyLibTopic); |
| | | svyLibTopicMapper.insertSvyLibTemplateScriptWjx(svyLibTopic); |
| | | } catch (Exception e) { |
| | | noExpiain(fileName.substring(0, fileName.length() - 5) + "出异常了1", fileContent); |
| | | continue a; |
| | |
| | | String text = label.text(); |
| | | //将题目存库 |
| | | // item = item + "------" + text; |
| | | SvyLibTopicoption svyLibTopicoption = new SvyLibTopicoption(); |
| | | svyLibTopicoption.setTopicid(svyLibTopic.getTopicid()); |
| | | svyLibTopicoption.setSvyid(svyLibTitle.getSvyid()); |
| | | SvyLibTemplateTargetoptionWjx svyLibTopicoption = new SvyLibTemplateTargetoptionWjx(); |
| | | svyLibTopicoption.setScriptid(svyLibTopic.getId()); |
| | | svyLibTopicoption.setTemplateID(svyLibTitle.getSvyid()); |
| | | svyLibTopicoption.setSort(i); |
| | | svyLibTopicoption.setOptioncode(IdUtils.simpleUUID()); |
| | | svyLibTopicoption.setGuid(IdUtils.simpleUUID()); |
| | | svyLibTopicoption.setOptioncontent(text); |
| | | svyLibTopicoption.setDelFlag("0"); |
| | | svyLibTopicoption.setIsupload(0L); |
| | | try { |
| | | svyLibTopicoptionMapper.insertSvyLibTopicoption(svyLibTopicoption); |
| | | svyLibTopicoptionMapper.insertSvyLibTemplateTargetoptionWjx(svyLibTopicoption); |
| | | } catch (Exception e) { |
| | | noExpiain(fileName.substring(0, fileName.length() - 5) + "出异常了2", fileContent); |
| | | continue a; |
| | |
| | | } else { |
| | | |
| | | //将题目保存到表中 |
| | | |
| | | |
| | | Elements elementsByClass2 = element.getElementsByClass("ui-control-group ui-matrix"); |
| | | if (elementsByClass2.size() > 0) { |
| | | SvyLibTopic svyLibTopic2 = new SvyLibTopic(); |
| | | SvyLibTemplateScriptWjx svyLibTopic2 = new SvyLibTemplateScriptWjx(); |
| | | svyLibTopic2.setSvyid(svyLibTitle.getSvyid()); |
| | | svyLibTopic2.setTopiccode(IdUtils.simpleUUID()); |
| | | svyLibTopic2.setTopic(legend); |
| | | svyLibTopic2.setSeqno(IdUtils.simpleUUID()); |
| | | svyLibTopic2.setScriptContent(legend); |
| | | svyLibTopic2.setDelFlag("0"); |
| | | svyLibTopic.setIsupload(0L); |
| | | svyLibTopic2.setTopictype("4"); |
| | | svyLibTopic2.setScriptType("4"); |
| | | svyLibTopic2.setOrgid(fileName); |
| | | try { |
| | | svyLibTopicMapper.insertSvyLibTopic(svyLibTopic2); |
| | | svyLibTopicMapper.insertSvyLibTemplateScriptWjx(svyLibTopic2); |
| | | } catch (Exception e) { |
| | | noExpiain(fileName.substring(0, fileName.length() - 5) + "出异常了22", fileContent); |
| | | continue a; |
| | |
| | | direction = direction + ele.text() + "☆"; |
| | | } |
| | | SvyLibTopicdirection svyLibTopicdirection = new SvyLibTopicdirection(); |
| | | svyLibTopicdirection.setTopicid(svyLibTopic2.getTopicid()); |
| | | svyLibTopicdirection.setTopicid(svyLibTopic2.getId()); |
| | | svyLibTopicdirection.setDirection(direction); |
| | | svyLibTopicdirection.setTransverse(transverse); |
| | | svyLibTopicdirectionMapper.insertSvyLibTopicdirection(svyLibTopicdirection); |
| | |
| | | |
| | | |
| | | //将题目保存到表中 |
| | | SvyLibTopic svyLibTopic3 = new SvyLibTopic(); |
| | | SvyLibTemplateScriptWjx svyLibTopic3 = new SvyLibTemplateScriptWjx(); |
| | | svyLibTopic3.setSvyid(svyLibTitle.getSvyid()); |
| | | svyLibTopic3.setTopiccode(IdUtils.simpleUUID()); |
| | | svyLibTopic3.setTopic(legend); |
| | | svyLibTopic3.setSeqno(IdUtils.simpleUUID()); |
| | | svyLibTopic3.setScriptContent(legend); |
| | | svyLibTopic3.setDelFlag("0"); |
| | | svyLibTopic3.setIsupload(0L); |
| | | svyLibTopic3.setTopictype("3"); |
| | | svyLibTopic3.setScriptType("3"); |
| | | svyLibTopic3.setOrgid(fileName); |
| | | try { |
| | | svyLibTopicMapper.insertSvyLibTopic(svyLibTopic3); |
| | | svyLibTopicMapper.insertSvyLibTemplateScriptWjx(svyLibTopic3); |
| | | } catch (Exception e) { |
| | | noExpiain(fileName.substring(0, fileName.length() - 5) + "出异常了33", fileContent); |
| | | continue a; |
| | |
| | | } |
| | | |
| | | |
| | | 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); |