My task was to have a series of shortcuts like Windows + F1 to play a sound through a microphone as though I said it. This would be good for trolling in multiplayer games (classic Duke Nukem soundboard stuff) or in my case for saying common things while I work as a helpdesk technician "Thanks for calling, how may I assist you today?" I like to sound less robotic to the people who monitor my calls for quality assurance purposes, so I produced a few versions of each phrase I wanted to use and exported them as .wav files using Audacity and cleaning up the audio with noise reduction. That's right, I used a robot to sound less robotic.
My code is pretty simple. I used lists to pick one of my recordings at random each time I use the hotkey. In fact, this is the first and it became the final version of the code.
Code: Select all
#persistent
list1= aGreeting1.wav, aGreeting2.wav, aGreeting3.wav
listA:=strSplit(list1, ",") ; A = Array
list2= zFarewell1.wav, zFarewell2.wav, zFarewell3.wav, zFarewell4.wav
listB:=strSplit(list2, ",") ; B = Array
#F1::
random, choice, 1, % listA.maxIndex() ; random between 1 and the total item count.
response:=trim(listA[choice])
SoundPlay, %response%
return
#F2::SoundPlay, cancel.wav
#Space::SoundPlay, cancel.wav
#F3::
random, choice, 1, % listB.maxIndex() ; random between 1 and the total item count.
response:=trim(listB[choice])
SoundPlay, %response%
return
But now comes the part where I hope I'm writing in enough search engine optimization. I beat my head against the wall to find out how to make these sounds play as though through my USB headset microphone. I wanted to be able to talk to a customer after my computer greeted them, and have the customer have no idea that it was any different (except that my prerecorded response had all the enthusiasm that my QM team demands and would listen for).
I stumbled upon Virtual Audio Cable and downloaded some free trial, which didn't seem right. Then I found this video and in its description I found this link. I'm not confident that either of those links will persist as long as this post will, so here's the text, except that I updated it as of 6/15/2021 (original post mid-February 2021):
Do exactly that. My work's virtual phone program is playing into my USB headset and listening from Virtual Audio Cable. But that isn't right still. In order for the computer to basically work like normal except AutoHotkey sends noises to Virtual Audio Cable, I had to use Windows 10's Sound Settings (right click on the volume icon in the system tray and Open Sound Settings - scroll down and click App volume and device preferences). AutoHotkey didn't show up in this list for me, so while I had that window open I ran my code and played a file. Then "AutoHotkey Unicode 64-bit" showed up in the list and I could set its default output and input. I don't do anything with input into AutoHotkey, but I still set the output as CABLE Input and the input as CABLE Output. I'm sure there's an easier way to say that.If you have Lync, Jabber, Skype or any other conferencing system in which you want to use more than one microphone, this tutorial is for you.
https://www.youtube.com/watch?v=TQHP1PZBPvc
Download Virtual Audio Cable from this page (most likely you want the 64 bit version)
Install Virtual Audio Cable – do NOT touch the software after the install
Go to your Windows RECORDING DEVICES – do NOT touch your PLAYBACK DEVICES
Double click on each Microphone you want to use, click the SOUNDS TAB, click LISTEN TO THIS DEVICE and set the drop down to "CABLE-Input (VB-Audio Virtual Cable)"
In RECORDING DEVICES, right click on "CABLE-Input (VB-Audio Virtual Cable)" and set it to DEFAULT
Now you are done, other than to make sure that the software in question (Skype, Lync…) is set to use either your Windows Default Recording Device OR "CABLE-Input (VB-Audio Virtual Cable)"
I tested this by using my virtual phone system to echo a test call back to me. I didn't have to tweak the volume any to get it to sound right, but you may have to do that. If you want to test this, try using Skype or something similar and use its echo test call feature.
The only thing I'd like to add to this is some kind of notification that shows while a sound file is being played. My very bogus workaround for this is to open the recording devices window (right-click the sound icon in your system tray and select "Sounds" then go to the recording tab) and to have this sitting somewhere barely visible on my screen so I can see the meter rise and fall as my robot talks.
Troubleshooting:
When I go back into Sound Settings, AutoHotkey isn't in there anymore and suddenly it doesn't work. I have to play a sound, get it in the list, and then change the playback device to something else and then back to whatever I want it to be (headphones in my case. See below for where I mean).
Once in a while a Windows or driver update may stop the bit where the headset microphone is being "listened" to by the VAC. Just test it out before using it. I noticed that if I speak into the microphone and both bars don't rise in the recording window, then the listening isn't happening.
Edits: This post was edited twice: once to update links and then immediately again to fix formatting and combine my previous replies into the main post. I've since deleted the replies.