0
이름을 말한 Cortana에 대한 명령이 있지만 앱이 열려있는 경우에만 작동합니다. 닫힌 응용 프로그램에서 명령을 발음하면 응용 프로그램이 열리지 만 명령이 시작되지 않습니다. 앱을 실제로 열려면 어떻게해야합니까?Cortana UWP로 앱 열기
CortanaCommand.xml :
<CommandSet xml:lang="en-us" Name="ExampleAppCommandSet_en-us">
<CommandPrefix> Open name </CommandPrefix>
<Example> Find a name </Example>
<Command Name="FindName">
<Example> Find name </Example>
<ListenFor> Find name </ListenFor>
<ListenFor> Find name </ListenFor>
<Feedback> Find name </Feedback>
<Navigate/>
</Command>
App.xaml.cs를 (공개 응용 프로그램) :
public App()
{
Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
Microsoft.ApplicationInsights.WindowsCollectors.Metadata |
Microsoft.ApplicationInsights.WindowsCollectors.Session);
this.InitializeComponent();
this.Suspending += OnSuspending;
}
App.xaml.cs를 (OnActivated) :
protected override void OnActivated(IActivatedEventArgs e)
{
// Was the app activated by a voice command?
if (e.Kind != Windows.ApplicationModel.Activation.ActivationKind.VoiceCommand)
{
return;
}
var commandArgs = e as Windows.ApplicationModel.Activation.VoiceCommandActivatedEventArgs;
var speechRecognitionResult = commandArgs.Result;
string voiceCommandName = speechRecognitionResult.RulePath[0];
string textSpoken = speechRecognitionResult.Text;
Frame rootFrame = Window.Current.Content as Frame;
MainPage page = rootFrame.Content as MainPage;
if (page == null)
{
return;
}
switch (voiceCommandName)
{
case "FindName":
page.FindNameInList();
break;
default:
// There is no match for the voice command name.
break;
}
}
MainPage.xaml.cs :
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
var storageFile =
await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(
new Uri("ms-appx:///CortanaCommand.xml"));
await Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinitionManager
.InstallCommandDefinitionsFromStorageFileAsync(storageFile);
}
public async void FindNameInList()
{
MediaElement mediaElement = new MediaElement();
// The object for controlling the speech synthesis engine (voice).
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
// Generate the audio stream from plain text.
SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Your name, is, Jhon");
// Send the stream to the media object.
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}
미리 감사드립니다.
그래서 이것은 UWP에서 사용할 수없는 것입니다. 가장 가까운 곳은 코르 타나 앱을 열고 "FindName"이라고 말하면 완벽하게 잘 작동합니다. –