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);
}}}}