2

Windows has API for speech recognition, it also provides system apps that perform speech recognition and execute recognised command. Is there a way/API to send commands programmatically? Text and Audio file is acceptable. But please don't suggest using virtual mic, thanks!

Clarification:

playing back audio outloud is not the way

1 Answers1

0

Since an audio file is acceptable, you can use the text to speech API to generate speech by the entered command and save that to a file that you can pass to the speech recognition API.

    SpeechSynthesizer ss = new SpeechSynthesizer();
    ss.Volume = 100;
    ss.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
    ss.SetOutputToWaveFile(@"C:\Command.wav");
    string command = Console.ReadLine();
    ss.Speak(command);

Although I have found one question talking about the quality of the file and has an answer on how to fix it, either way if it recognizes it with no issues then you don't have to deal with the quality.

Yoh
  • 63
  • 10
  • I'd like to add that I didn't test the code, my Visual Studio is updating right now and it's taking a while and the code provided in the first question is a bit old, let me know how it works out. – Yoh Aug 16 '22 at 16:11
  • playing back audio outloud doesn't fit, sorry – Paul Nadolinskyi Aug 17 '22 at 09:09
  • It does not play audio out loud? Did you test the code? It just saves the speech into a file and you can feed that file to your program and it will detect it. – Yoh Aug 17 '22 at 19:22
  • the whole point of this question is not to generate audio, but to make PC run command (i.e. make system to perform command) – Paul Nadolinskyi Aug 18 '22 at 08:39
  • 1
    Your program works with speech recognition, speech recognition = audio, if you don't want users to use a microphone and you don't want to simulate the speaking, then how are you going to do it? What is stopping you from using an audio file especially that the API supports it? It does not speak through the speakers (no audio is being played), so the user wouldn't know a thing. – Yoh Aug 18 '22 at 17:37