TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Afraz Afaq
NA
2
733
How do I handel events like speech or key press in C# Servic
Sep 26 2017 2:34 AM
I am trying to make a program basically a voice support so that recognizes speech and does the corresponding work I want this program to work even after the pc is in sleep state thats why i want service but after installing service successfully it does not hear any voice.
public
partial
class
Service1 : ServiceBase
{
SpeechSynthesizer s =
new
SpeechSynthesizer();
SpeechRecognitionEngine rec =
new
SpeechRecognitionEngine();
Choices list =
new
Choices();
public
Service1()
{
s.SelectVoiceByHints(VoiceGender.Male)
s.Speak(
"heyy"
);
list.Add(
new
String[] {
"hello"
,
"how are you"
});
Grammar gr =
new
Grammar(
new
GrammarBuilder(list));
try
{
rec.RequestRecognizerUpdate();
rec.LoadGrammar(gr);
rec.SpeechRecognized += rec_speachrecocnized;
rec.SetInputToDefaultAudioDevice();
rec.RecognizeAsync(RecognizeMode.Multiple);
}
catch
{
return
; };
InitializeComponent();
}
public
void
speak(String h)
{
s.Speak(h);
}
private
void
rec_speachrecocnized(
object
sender, SpeechRecognizedEventArgs e)
{
String r = e.Result.Text;
if
(r ==
"hello"
)
{
speak(
"hello"
);
}
if
(r ==
"how are you"
)
{
speak(
"fine"
);
}
}
protected
override
void
OnStart(
string
[] args)
{
}
protected
override
void
OnStop()
{
}
}
Attachment:
Service1.rar
Reply
Answers (
1
)
I am Trying To Build An Empty Project In Visual 2017?
Submitting Universal Windows App To Store ?