-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathVoiceAccessUserControl.cpp
More file actions
209 lines (184 loc) · 6.9 KB
/
VoiceAccessUserControl.cpp
File metadata and controls
209 lines (184 loc) · 6.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright © Microsoft Corporation. All rights reserved
#pragma once
#using <mscorlib.dll>
#using <System.dll>
#using <PresentationCore.dll>
#using <PresentationFramework.dll>
#using <WindowsBase.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Windows;
using namespace System::Windows::Controls;
namespace Microsoft { namespace Samples { namespace Speech { namespace VoiceAccess {
/// <summary>
/// Voice Access User Control implementation in C++/CLI
/// Displays current mode (Translator/Recognizer) based on m_useTranslatorConfig flag
/// </summary>
public ref class VoiceAccessUserControl : UserControl, INotifyPropertyChanged
{
private:
/// <summary>
/// Flag to determine if translator mode is active
/// true = Translator Mode, false = Recognizer Mode
/// </summary>
bool m_useTranslatorConfig;
/// <summary>
/// Property for the mode text displayed in the UI
/// </summary>
String^ m_modeText;
/// <summary>
/// UI Elements
/// </summary>
TextBlock^ ModeTextBlock;
TextBlock^ StatusTextBlock;
Button^ ToggleModeButton;
Button^ StartButton;
Button^ StopButton;
public:
/// <summary>
/// Default constructor
/// </summary>
VoiceAccessUserControl()
{
m_useTranslatorConfig = false;
m_modeText = "";
InitializeComponent();
DataContext = this;
// Initialize with default mode
UpdateModeText();
UpdateStatus("Voice Access Control initialized.");
}
/// <summary>
/// Gets the current mode text
/// </summary>
property String^ ModeText
{
String^ get() { return m_modeText; }
private: void set(String^ value)
{
if (m_modeText != value)
{
m_modeText = value;
OnPropertyChanged("ModeText");
}
}
}
/// <summary>
/// Gets or sets the translator configuration flag
/// </summary>
property bool UseTranslatorConfig
{
bool get() { return m_useTranslatorConfig; }
void set(bool value)
{
if (m_useTranslatorConfig != value)
{
m_useTranslatorConfig = value;
UpdateModeText();
OnPropertyChanged("UseTranslatorConfig");
}
}
}
/// <summary>
/// Property changed event for data binding
/// </summary>
virtual event PropertyChangedEventHandler^ PropertyChanged;
private:
/// <summary>
/// Initialize the user control components
/// </summary>
void InitializeComponent()
{
// Load XAML content
String^ xamlUri = "pack://application:,,,/VoiceAccessUserControl.xaml";
System::Uri^ uri = gcnew System::Uri(xamlUri, System::UriKind::Absolute);
System::Windows::Application::LoadComponent(this, uri);
// Get references to named elements
ModeTextBlock = safe_cast<TextBlock^>(FindName("ModeTextBlock"));
StatusTextBlock = safe_cast<TextBlock^>(FindName("StatusTextBlock"));
ToggleModeButton = safe_cast<Button^>(FindName("ToggleModeButton"));
StartButton = safe_cast<Button^>(FindName("StartButton"));
StopButton = safe_cast<Button^>(FindName("StopButton"));
// Wire up event handlers
if (ToggleModeButton != nullptr)
ToggleModeButton->Click += gcnew RoutedEventHandler(this, &VoiceAccessUserControl::ToggleModeButton_Click);
if (StartButton != nullptr)
StartButton->Click += gcnew RoutedEventHandler(this, &VoiceAccessUserControl::StartButton_Click);
if (StopButton != nullptr)
StopButton->Click += gcnew RoutedEventHandler(this, &VoiceAccessUserControl::StopButton_Click);
}
/// <summary>
/// Updates the mode text based on the current configuration
/// </summary>
void UpdateModeText()
{
ModeText = m_useTranslatorConfig ? "Translator Mode" : "Recognizer Mode";
}
/// <summary>
/// Updates the status text display
/// </summary>
/// <param name="message">Status message to display</param>
void UpdateStatus(String^ message)
{
if (StatusTextBlock != nullptr)
{
DateTime now = DateTime::Now;
StatusTextBlock->Text = String::Format("[{0:HH:mm:ss}] {1}", now, message);
}
}
/// <summary>
/// Raises the PropertyChanged event
/// </summary>
/// <param name="propertyName">Name of the property that changed</param>
void OnPropertyChanged(String^ propertyName)
{
PropertyChangedEventArgs^ args = gcnew PropertyChangedEventArgs(propertyName);
PropertyChanged(this, args);
}
/// <summary>
/// Toggle mode button click handler
/// </summary>
void ToggleModeButton_Click(Object^ sender, RoutedEventArgs^ e)
{
UseTranslatorConfig = !UseTranslatorConfig;
UpdateStatus(String::Format("Mode changed to: {0}", ModeText));
}
/// <summary>
/// Start button click handler
/// </summary>
void StartButton_Click(Object^ sender, RoutedEventArgs^ e)
{
UpdateStatus(String::Format("Starting {0}...", ModeText));
// Simulate starting the appropriate service
if (m_useTranslatorConfig)
{
UpdateStatus("Translator service started. Ready to translate speech.");
}
else
{
UpdateStatus("Speech recognizer started. Ready to recognize speech.");
}
}
/// <summary>
/// Stop button click handler
/// </summary>
void StopButton_Click(Object^ sender, RoutedEventArgs^ e)
{
UpdateStatus(String::Format("Stopping {0}...", ModeText));
// Simulate stopping the service
if (m_useTranslatorConfig)
{
UpdateStatus("Translator service stopped.");
}
else
{
UpdateStatus("Speech recognizer stopped.");
}
}
};
}}}} // namespace Microsoft::Samples::Speech::VoiceAccess