Skip to content

Instantly share code, notes, and snippets.

@jaydp17
Created March 25, 2013 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaydp17/5237097 to your computer and use it in GitHub Desktop.
Save jaydp17/5237097 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.ComponentModel;
using System.Windows.Data;
using Windows.Phone.Speech.Synthesis;
using System.Threading;
using System.Threading.Tasks;
namespace PhoneApp2
{
public partial class MainPage : PhoneApplicationPage
{
private SpeechSynthesizer synthesizer;
CancellationTokenSource cts = null;
List<String> text;
int count = 0;
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
synthesizer = new SpeechSynthesizer();
text = new List<string>() { "hello", "jaydeep", "I'm", "sirri", "I'm", "here", "to", "help", "you", "hello", "jaydeep", "I'm", "sirri", "I'm", "here", "to", "help", "you" };
}
private async void ScreenTap(object sender, System.Windows.Input.GestureEventArgs e)
{
if (cts == null)
{
cts = new CancellationTokenSource();
try
{
ReadText(cts.Token);
}
catch (OperationCanceledException)
{
}
}
else
{
cts.Cancel();
cts = null;
}
}
private async Task ReadText(CancellationToken token)
{
for (; count < text.Count; count++)
{
token.ThrowIfCancellationRequested();
await synthesizer.SpeakTextAsync(text[count]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment