Advertisement
tabnation

ahk text to voice for kids

Nov 22nd, 2022
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1.  
  2. f4::
  3. getSelectionCoords(x_start, x_end, y_start, y_end)
  4. return
  5.  
  6. ; creates a click-and-drag selection box to specify an area
  7. getSelectionCoords(ByRef x_start, ByRef x_end, ByRef y_start, ByRef y_end) {
  8. ;Mask Screen
  9. Gui, Color, FFFFFF
  10. Gui +LastFound
  11. WinSet, Transparent, 50
  12. Gui, -Caption
  13. Gui, +AlwaysOnTop
  14. Gui, Show, x0 y0 h%A_ScreenHeight% w%A_ScreenWidth%,"AutoHotkeySnapshotApp"
  15.  
  16. ;Drag Mouse
  17. CoordMode, Mouse, Screen
  18. CoordMode, Tooltip, Screen
  19. WinGet, hw_frame_m,ID,"AutoHotkeySnapshotApp"
  20. hdc_frame_m := DllCall( "GetDC", "uint", hw_frame_m)
  21. KeyWait, LButton, D
  22. MouseGetPos, scan_x_start, scan_y_start
  23. Loop
  24. {
  25. Sleep, 10
  26. KeyIsDown := GetKeyState("LButton")
  27. if (KeyIsDown = 1)
  28. {
  29. MouseGetPos, scan_x, scan_y
  30. DllCall( "gdi32.dll\Rectangle", "uint", hdc_frame_m, "int", 0,"int",0,"int", A_ScreenWidth,"int",A_ScreenWidth)
  31. DllCall( "gdi32.dll\Rectangle", "uint", hdc_frame_m, "int", scan_x_start,"int",scan_y_start,"int", scan_x,"int",scan_y)
  32. } else {
  33. break
  34. }
  35. }
  36.  
  37. ;KeyWait, LButton, U
  38. MouseGetPos, scan_x_end, scan_y_end
  39. Gui Destroy
  40.  
  41. if (scan_x_start < scan_x_end)
  42. {
  43. x_start := scan_x_start
  44. x_end := scan_x_end
  45. } else {
  46. x_start := scan_x_end
  47. x_end := scan_x_start
  48. }
  49.  
  50. if (scan_y_start < scan_y_end)
  51. {
  52. y_start := scan_y_start
  53. y_end := scan_y_end
  54. } else {
  55. y_start := scan_y_end
  56. y_end := scan_y_start
  57. }
  58. }
  59.  
  60.  
  61. f1::
  62. RunWait, C:\Users\Thom\Desktop\Capture2Text_v3.9\Capture2Text.exe %x_start% %y_start% %x_end% %y_end%
  63. ;msgbox, %clipboard%
  64. ComObjCreate("SAPI.SpVoice").Speak(Clipboard)
  65. return
  66.  
  67.  
  68. f2:: ;change voice type
  69. if (SUCCEEDED(SpGetCategoryFromId(SPCAT_VOICES := "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices", cpSpObjectTokenCategory)))
  70. {
  71. hr := DllCall(NumGet(NumGet(cpSpObjectTokenCategory+0)+18*A_PtrSize), "Ptr", cpSpObjectTokenCategory, "Ptr", 0, "Ptr", 0, "Ptr*", cpSpEnumTokens)
  72.  
  73. if (SUCCEEDED(hr))
  74. {
  75. hr := DllCall(NumGet(NumGet(cpSpEnumTokens+0)+8*A_PtrSize), "Ptr", cpSpEnumTokens, "UInt*", tokenCount)
  76. if (SUCCEEDED(hr))
  77. {
  78. voices := Object()
  79. Loop %tokenCount% {
  80. hr := DllCall(NumGet(NumGet(cpSpEnumTokens+0)+7*A_PtrSize), "Ptr", cpSpEnumTokens, "UInt", A_Index - 1, "Ptr*", pToken)
  81. if (FAILED(hr)) {
  82. MsgBox Bailing out
  83. ExitApp 1
  84. }
  85. hr := DllCall(NumGet(NumGet(pToken+0)+6*A_PtrSize), "Ptr", pToken, "Ptr", 0, "Ptr*", pszValue)
  86. if (FAILED(hr)) {
  87. MsgBox Bailing out
  88. ExitApp 2
  89. }
  90. hr := DllCall(NumGet(NumGet(pToken+0)+16*A_PtrSize), "Ptr", pToken, "Ptr*", pszCoMemTokenId)
  91. if (FAILED(hr)) {
  92. MsgBox Bailing out
  93. ExitApp 3
  94. }
  95. voices[StrGet(pszCoMemTokenId, "UTF-16")] := StrGet(pszValue, "UTF-16")
  96. DllCall("ole32\CoTaskMemFree", "Ptr", pszValue)
  97. DllCall("ole32\CoTaskMemFree", "Ptr", pszCoMemTokenId)
  98. ObjRelease(pToken)
  99. }
  100. prompt := "Pick a voice by its number:"
  101. for k, v in voices
  102. prompt .= "`r`n" . A_Index . ": " v
  103. InputBox, TheChosenOne,, %prompt%
  104. if (ErrorLevel == 0) {
  105. for k, v in voices {
  106. if (A_Index == TheChosenOne) {
  107. hr := DllCall(NumGet(NumGet(cpSpObjectTokenCategory+0)+19*A_PtrSize), "Ptr", cpSpObjectTokenCategory, "WStr", k)
  108. break
  109. }
  110. }
  111. }
  112. }
  113. ObjRelease(cpSpEnumTokens)
  114. }
  115.  
  116. ObjRelease(cpSpObjectTokenCategory)
  117. }
  118.  
  119. SpGetCategoryFromId(pszCategoryId, ByRef ppCategory, fCreateIfNotExist := False)
  120. {
  121. static CLSID_SpObjectTokenCategory := "{A910187F-0C7A-45AC-92CC-59EDAFB77B53}"
  122. ,ISpObjectTokenCategory := "{2D3D3845-39AF-4850-BBF9-40B49780011D}"
  123.  
  124. hr := 0
  125. try {
  126. cpTokenCategory := ComObjCreate(CLSID_SpObjectTokenCategory, ISpObjectTokenCategory)
  127. } catch e {
  128. ; No, A_LastError or ErrorLevel doesn't contain the error code on its own and I CBA to use CoCreateInstance directly
  129. if (RegExMatch(e.Message, "0[xX][0-9a-fA-F]+", errCode)) { ; https://stackoverflow.com/a/9221391
  130. hr := errCode + 0
  131. } else {
  132. hr := 0x80004005
  133. }
  134. }
  135.  
  136. if (SUCCEEDED(hr))
  137. {
  138. hr := DllCall(NumGet(NumGet(cpTokenCategory+0)+15*A_PtrSize), "Ptr", cpTokenCategory, "WStr", pszCategoryId, "Int", fCreateIfNotExist)
  139. }
  140.  
  141. if (SUCCEEDED(hr))
  142. {
  143. ppCategory := cpTokenCategory
  144. }
  145. else
  146. {
  147. if (cpTokenCategory)
  148. ObjRelease(cpTokenCategory)
  149. }
  150.  
  151. return hr
  152. }
  153.  
  154. SUCCEEDED(hr)
  155. {
  156. return hr != "" && hr >= 0x00
  157. }
  158.  
  159. FAILED(hr)
  160. {
  161. return hr == "" || hr < 0
  162. }
  163.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement