听书神器
2021/7/16 23:39:37
本文主要是介绍听书神器,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class Tingshu {
public static void main(String[] args) throws UnsupportedFlavorException, IOException, InterruptedException {
// TODO Auto-generated method stub
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
//接收一个字符串
StringSelection selection = new StringSelection("123");
//获得剪切板内容
clipboard.setContents(selection, null);
while (true) {
//拿到剪切板内容
Transferable transferable = clipboard.getContents(null); //先定义一个字符串 得到一个转换数据 得到字符串
String search = (String)transferable.getTransferData(DataFlavor.stringFlavor);
//读取一个新文件
Scanner scanner = new Scanner(new File("D:/456.txt"));
while (scanner.hasNext()) {
String aaa = scanner.nextLine();
if (aaa.contains(search)) {
} ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");
Dispatch sapo = sap.getObject();
try {
sap.setProperty("Volume", new Variant(100));
sap.setProperty("Rate", new Variant(5));
Variant defalutVoice = sap.getProperty("Voice");
Dispatch dispdefaultVoice = defalutVoice.toDispatch();
Variant allVoices = Dispatch.call(sapo, "GetVoices");
Dispatch dispVoices = allVoices.toDispatch();
Dispatch setvoice = Dispatch.call(dispVoices, "Item", new Variant(1)).toDispatch();
ActiveXComponent voiceActivex = new ActiveXComponent(dispdefaultVoice);
ActiveXComponent setvoiceActivex = new ActiveXComponent(setvoice);
Variant item = Dispatch.call(setvoiceActivex, "GetDescription");
Dispatch.call(sapo, "Speak", new Variant(aaa));
} catch (Exception e) {
e.printStackTrace();
} finally {
sapo.safeRelease();
sap.safeRelease();
}
Thread.sleep(50);
}}}}
这篇关于听书神器的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南