Created
March 25, 2013 13:30
-
-
Save jaydp17/5237097 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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