我们常常遇到一个陌生的英文单词却拿不准发音, 在 Mac 上我们有内建的快捷键 Option + Esc 来朗读单词, 而在 Windows 并没有内建的工具, 为此我写了这个脚本 speak.vbs. 使用时首先复制需要朗读的单词, 然后运行它即可朗读当前剪贴板里的第一个单词
我在使用时配合了 WinHotKey, 并关联了快捷键 Ctrl + Alt + S. 记得要 Uncheck Windows 的权限提醒
在 Linux 下 Speak Clipboard 有点异常简单了,只需要 Run 这一句,
xclip -o | espeak
你可以将它保存为一个 Bash 脚本,然后用快捷键执行它。
' 1. Get clipboard text
Set objHtml = CreateObject("htmlfile")
clipBoard = objHtml.ParentWindow.ClipboardData.GetData("text")
If clipBoard <> "" Then ' Do nothing if empty
Dim clipBoardText
clipBoardText = CStr(clipBoard)
clipBoardText = Trim(clipBoardText)
clipBoardText = LCase(clipBoardText)
splitText = Split(clipBoardText, " ")
textToSpeak = splitText(0) ' get only first word
' Test if it has chinese character to avoid error
Set objRegExp = New RegExp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "[^a-zA-Z0-9\s]"
doesWriteLog = True
If objRegExp.Test(clipBoardText) Then
textToSpeak = "character mistake"
doesWriteLog = false
End If
' 2. Speak it
Set sapi = CreateObject("sapi.spvoice")
If Len(textToSpeak) >= 30 Then
sapi.Speak "text too long"
doesWriteLog = false
ElseIf Len(textToSpeak) < 30 Then
sapi.Speak textToSpeak
End If
' 3. Save a log
Set fso = CreateObject("Scripting.FileSystemObject")
strFile = "words.txt"
' Read old
strLine = ""
If (fso.FileExists(strFile)) Then
Set objFileRead = fso.OpenTextFile(strFile)
Do Until objFileRead.AtEndOfStream
strLine = objFileRead.ReadLine
Loop
objFileRead.Close
End If
' Write new
Set objFileWrite = fso.CreateTextFile(strFile, True)
If doesWriteLog Then
objFileWrite.Write strLine + textToSpeak + " " & vbCrLf
Else
objFileWrite.Write strLine + " " & vbCrLf
End If
objFileWrite.Close
End If ' If clipboard empty
2019-01-03 20:24:07
解决了剪贴板有汉字会报错的 Bug。
2019-01-27 14:09:19
修复了剪贴板为空的 Bug。
2019-09-29 18:57:18
增加了 Linux 下 Speak Clipboard 的方法。