1
0
Fork 0
Browse Source

create a P.O.C. for a text-to-speech feature.

This is a very rough bit of code. This is for testing the possibilty/usability of having the program provide updates using the SpeechSynthesizer class. The initial intention is to have the program denote any change in power status ('gallery1' is now off', 'weld detected by factory1' Etc.) and, if it's any good, expand it from there.

The code changes made here are incomplete but I'm packing up for the day and going home -- it's late. I'm logging the current changes for future reference.
stable
Craig Oates 3 years ago
parent
commit
5d91fc5772
  1. 9
      src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml
  2. 15
      src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs

9
src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml

@ -7,9 +7,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource SystemControlAcrylicWindowBrush}">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="96"/>
<RowDefinition Height="Auto"/>
@ -28,6 +28,7 @@
<StackPanel Grid.Row="0" Orientation="Horizontal"
VerticalAlignment="Top">
<MediaElement Name="AudioUpdater" AutoPlay="False"/>
<Image Grid.Column="0" Width="88" Height="88" VerticalAlignment="Center"
Source="Images\logo.png"/>
<StackPanel Padding="8,0">
@ -231,8 +232,10 @@
Unchecked="LogToggle_Unchecked"
Checked="LogToggle_Checked"
IsChecked="True"/>
<Button x:Name="speech" Content="speak" Margin="10"
Click="speech_Click"/>
<HyperlinkButton x:Name="InfoButton" Grid.Column="0"
<HyperlinkButton x:Name="InfoButton" Grid.Column="0"
NavigateUri="http://www.nicolaellis.com"
FontFamily="Segoe MDL2 Assets" Content="&#xE946;"
Height="79" Width="79" VerticalAlignment="Center"

15
src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs

@ -2,6 +2,7 @@
using EyesAndEars.UWP.ViewModels;
using System;
using Windows.ApplicationModel;
using Windows.Media.SpeechSynthesis;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@ -11,6 +12,8 @@ namespace EyesAndEars.UWP {
MainPageVM _vm = new MainPageVM();
DispatcherTimer _dispatcherTimer = new DispatcherTimer();
// The object for controlling the speech synthesis engine (voice).
SpeechSynthesizer synth = new SpeechSynthesizer();
public MainPage() {
InitializeComponent();
@ -19,6 +22,14 @@ namespace EyesAndEars.UWP {
IntialiseRefreshTime();
}
private async void PlayText() {
// Generate the audio stream from plain text.
var stream = await synth.SynthesizeTextToStreamAsync("Hello World");
// Send the stream to the media object.
AudioUpdater.SetSource(stream, stream.ContentType);
AudioUpdater.Play();
}
void SetVersionNumber() {
var package = Package.Current;
var packageId = package.Id;
@ -84,5 +95,9 @@ namespace EyesAndEars.UWP {
private void LogToggle_Checked(object sender, RoutedEventArgs e) {
LogViewer.Visibility = Visibility.Visible;
}
private void speech_Click(object sender, RoutedEventArgs e) {
PlayText();
}
}
}