I recently found a great piece of code at Google search via speech in c# which helped me get an idea of how to turn user input and make it a text that the program can read and make it into a web search. This I got working. But now I wanted to see how much further I can take it, but for the past couple of weeks, I've been completely lost. I have a few questions regarding some adjustments I made to the original, which don't work.
default;
if (speech.ToLower().Contains("play song", "playlist", "play"))
{
string songName = speech.Replace(' ', ' ');
songName = speech.Replace(' ', ' ');
songName = System.Diagnostics.Process.Start(songName);
string song = @"C:file location of song" + songName;
System.Diagnostics.Process.Start(songName);
}
if (speech.ToLower().Contains("type"))
{
string wantedText = speech.Replace(' ', ' ');
wantedText = speech.Replace(' ', ' ');
wantedText = System.Diagnostics.Process.Start(wantedText);
string song = wantedText;
System.Diagnostics.Process.Start(wantedText);
}
break;
1: In order to play a song:
a) Having ("play song", "playlist", "play") made an error that said "No overload for method 'Contains' takes 3 arguments". How would I be able to make three or more arguments for this or any future speech to text code?
b) Using System.Diagnostics.Process.Start obviously wouldn't work, as far as I know. I have no idea what system to use for this situation.
2: In order to input direct type in the active window:
a) My lack of c# knowledge is hindering my ability to move forward with this idea. My first thought would be to treat it as if I were inputting speech to text on my command prompt, which I could do. But instead of the command prompt I want it to go to the active flashing text cursor in the active window, which could be Word or any search engine. I also think this could have a similar process as the original URL version in the link above.
b) Using System.Diagnostics.Process.Start obviously wouldn't work, as far as I know. I have no idea what system to use for this situation. Yes same question as from question 1b. I didn't know if it would be the same process for both.
1a) Contains
check if a string is contained within another string. If you want to check for multiple strings you need to call it multiple times like so:
var lower = speech.ToLower();
if (lower.Contains("play song") || lower.Contains("playlist") || lower.Contains("play"))
{ ... }
Now in this specific case you should be aware that the last condition also satisfies the first two so you could shorten the condition to:
if (speech.ToLower().Contains("play"))
and this will also cover the other two cases (because "playlist" and "play song" both contain the string "play").
1b) You will need to start a music player and pass the songname as an argument. You could try starting explorer and pass the songname as an argument. I think explorer automatically starts the program associated with the extension (if such an association exists).
2a) That's not really a question. SO is meant to help with specific problems regarding programming. You should first try and figure out what you want to do, then try to implement it and come back with specific questions about it.
2b) See 1b)