Я делаю личного помощника в C#. Хочу всякий раз, когда пользователь запускает помощника. Он будет работать как «Привет, NOVA» и просыпаться. Все идет хорошо, и я установил таймеры для анимации пользовательского интерфейса. Один для прибытия, а другой для отпуска. Каждый раз, когда пользователь спрашивает, запускается таймер прибытия timerNOVA
, а затем он приветствует пользователя. Если пользователь говорит: пока, NOVA! Он должен исчезнуть, но проблема в том, что всякий раз, когда я пытаюсь запустить его во второй раз, он показывает это - Он просто увеличивает и уменьшает элементы управления, как если бы оба таймера тикали, тогда как только 1 работает
Таймер запуска анимации - timerNOVA
Таймер окончания анимации - timer1
Проверить, говорит ли пользователь Good Bye Timer - utilTimer
Таймер Runtime Assistant - novaRUNTIME
код для базового класса
{
novaRUNTIME.Stop();
if (o == "disabled")
{
utilTimer.Start();
timerNova.Start();
}
else
{
}
}
private void timerNova_Tick(object sender, EventArgs e)
{
txtInput.Enabled = true;
txtInput.Visible = true;
progressNova.Value += 1;
txtInput.Width += 4;
if (progressNova.Value == 100 && txtInput.Width == 400)
{
//try
//{
timerNova.Stop();
SpeechSynthesizer _ss = new SpeechSynthesizer();
_ss.Rate = Settings.Default.novaRate;
_ss.SelectVoice(Properties.Settings.Default.novaVoice);
_ss.SpeakCompleted += _ss_SpeakCompleted;
_ss.SpeakAsync("Hello there, I am NOVA and I am your business assistant. How may I help you?");
o = "enabled";
//}
//catch
//{
//}
}
}
private void _ss_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
{
txtInput.IconRight = Resources.voice;
utilTimer.Start();
NOVA.Core.RecognizeAsync();
}
private void timer1_Tick(object sender, EventArgs e)
{
progressNova.Value -= 1;
txtInput.Width -= 4;
if (progressNova.Value == 0 && txtInput.Width == 0)
{
timer1.Stop();
txtInput.Visible = false;
txtInput.Enabled = false;
o = "disabled";
}
}
private void byeNovaToolStripMenuItem_Click(object sender, EventArgs e)
{
SpeechSynthesizer _ss = new SpeechSynthesizer();
_ss.Rate = Settings.Default.novaRate;
_ss.SelectVoice(Properties.Settings.Default.novaVoice);
_ss.SpeakAsync("Good Bye, see you soon");
timer1.Start();
}
private void txtInput_IconRightClick(object sender, EventArgs e)
{
utilTimer.Start();
Core.RecognizeAsync();
}
private void utilTimer_Tick(object sender, EventArgs e)
{
if (Core.returnValue == "Close")
{
timer1.Start();
utilTimer.Stop();
}
else if(Core.returnValue == "None")
{
utilTimer.Stop();
}
else
{
}
}
SpeechRecognitionEngine engine;
Choices commands;
private void novaRUNTIME_Tick(object sender, EventArgs e)
{
engine = new SpeechRecognitionEngine();
commands = new Choices();
Choices cs = new Choices();
cs.Add(new string[]
{
"Hey Nova", "Hello Nova", "What's up Nova" , "Good Morning Nova", "Good Afternoon Nova"
});
GrammarBuilder gm = new GrammarBuilder(cs);
Grammar g = new Grammar(gm);
engine.LoadGrammarAsync(g);
engine.SetInputToDefaultAudioDevice();
engine.RecognizeAsync(RecognizeMode.Single);
engine.SpeechRecognized += Engine_SpeechRecognized;
}
int i = 0;
private void Engine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
i++;
if (i == 1)
{
novaRUNTIME.Stop();
timerNova.Start();
}
else
{
}
}
Базовый класс для помощника
static SpeechRecognitionEngine engine;
static Choices commands;
public static string returnValue = " ";
public static void RecognizeAsync()
{
engine = new SpeechRecognitionEngine();
commands = new Choices();
Choices cs = new Choices();
cs.Add(new string[]
{
"What are my business stats", "What are my business statistics", "How are you?" , "Do a barrel roll", "Bye Nova"
});
GrammarBuilder gm = new GrammarBuilder(cs);
Grammar g = new Grammar(gm);
engine.LoadGrammarAsync(g);
engine.SetInputToDefaultAudioDevice();
engine.RecognizeAsync(RecognizeMode.Multiple);
engine.SpeechRecognized += Engine_SpeechRecognized;
engine.SpeechRecognitionRejected += Engine_SpeechRecognitionRejected;
}
public static void Engine_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
{
SpeechSynthesizer _ss = new SpeechSynthesizer();
_ss.Rate = Settings.Default.novaRate;
_ss.SelectVoice(Properties.Settings.Default.novaVoice);
_ss.SpeakAsync("Sorry, I couldn't get that!");
engine.Dispose();
}
public static void Engine_SpeechRecognized(object sender, SpeechRecognizedEventArgs resultFound)
{
if (resultFound.Result.Text == "How are you?")
{
string[] helloQuotes =
{
"I am working on my business, you do your business, Deal!", "I am well as I am always usual, I am healthy, wealthy and wise", "I am sick, Get me too the hospital!"
};
SpeechSynthesizer _ss = new SpeechSynthesizer();
_ss.Rate = Settings.Default.novaRate;
_ss.SelectVoice(Properties.Settings.Default.novaVoice);
_ss.SpeakAsync(helloQuotes[new Random().Next(0, helloQuotes.Length)]);
engine.Dispose();
returnValue = "None";
}
else if (resultFound.Result.Text == "Do a barrel roll")
{
SpeechSynthesizer _ss = new SpeechSynthesizer();
_ss.Rate = Settings.Default.novaRate;
_ss.SelectVoice(Properties.Settings.Default.novaVoice);
_ss.SpeakAsync("I am not Google Assistant, so I don't know what is barrel roll!");
engine.Dispose();
returnValue = "None";
}
else if (resultFound.Result.Text == "Bye Nova")
{
returnValue = "Close";
SpeechSynthesizer _ss = new SpeechSynthesizer();
_ss.Rate = Settings.Default.novaRate;
_ss.SelectVoice(Properties.Settings.Default.novaVoice);
_ss.SpeakAsync("Good Bye, see you soon");
engine.Dispose();
}
}
Видео -> https://vimeo.com/user120908515/review/445133614/4c90900641