本文整理汇总了C#中SpeechSynthesizer.SpeakTextAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SpeechSynthesizer.SpeakTextAsync方法的具体用法?C# SpeechSynthesizer.SpeakTextAsync怎么用?C# SpeechSynthesizer.SpeakTextAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpeechSynthesizer
的用法示例。
在下文中一共展示了SpeechSynthesizer.SpeakTextAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: handleDownloadStringComplete
private void handleDownloadStringComplete(object sender, DownloadStringCompletedEventArgs e)
{
if (Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsNetworkAvailable)
{
XNamespace media = XNamespace.Get("http://search.yahoo.com/mrss/");
titles = System.Xml.Linq.XElement.Parse(e.Result).Descendants("title")
.Where(m => m.Parent.Name == "item")
.Select(m => m.Value)
.ToArray();
descriptions = XElement.Parse(e.Result).Descendants("description")
.Where(m => m.Parent.Name == "item")
.Select(m => m.Value)
.ToArray();
images = XElement.Parse(e.Result).Descendants(media + "thumbnail")
.Where(m => m.Parent.Name == "item")
.Select(m => m.Attribute("url").Value)
.ToArray();
SpeechSynthesizer synth = new SpeechSynthesizer();
synth.SpeakTextAsync(titles[0]).Completed += new AsyncActionCompletedHandler(delegate(IAsyncAction action, AsyncStatus status)
{
synth.SpeakTextAsync(descriptions[0]);
});
UpdatePrimaryTile(titles[0], images[0]);
}
else
{
MessageBox.Show("No network is available...");
}
}
示例2: ReadAloud_Click
private void ReadAloud_Click(object sender, RoutedEventArgs e)
{
var sync = new SpeechSynthesizer();
// auf Ende des Vorlesevorganges wird nicht gewartet
sync.SpeakTextAsync(TextToRead.Text);
}
示例3: Speak
private async void Speak()
{
SpeechSynthesizer ss = new SpeechSynthesizer();
VoiceInformation vi = InstalledVoices.All.Where(v => v.Language == "en-EN" && v.Gender == VoiceGender.Male).FirstOrDefault();
ss.SetVoice(vi);
int rand=(int)RandomService.Instance.getRand(0, 3);
string answer="";
switch (rand)
{
case 0:
answer = "yes";
break;
case 1:
answer = "no";
break;
case 2:
answer = "maybe";
break;
case 3:
answer = "I don't know";
break;
}
AnswerText.Text = answer;
await ss.SpeakTextAsync(answer);
}
示例4: SpeakClick
private async void SpeakClick(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(inputTextBox.Text))
MessageBox.Show("Introduce algun texto a leer.");
else
{
try
{
SpeechSynthesizer synth = new SpeechSynthesizer();
var voices = InstalledVoices.All.Where(v => v.Language == "es-ES").OrderByDescending(v => v.Gender);
VoiceGender gender = VoiceGender.Male;
if (rbMale.IsChecked == true)
gender = VoiceGender.Male;
else
gender = VoiceGender.Female;
synth.SetVoice(voices.Where(v => v.Gender == gender).FirstOrDefault());
await synth.SpeakTextAsync(inputTextBox.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
示例5: Speak
public static async Task Speak(string text)
{
ExceptionDispatchInfo capturedException = null;
using (var speech = new SpeechSynthesizer())
{
try
{
await speech.SpeakTextAsync(text);
}
catch (Exception ex)
{
capturedException = ExceptionDispatchInfo.Capture(ex);
}
if (capturedException != null)
{
MessageBox.Show(capturedException.SourceException.Message);
//capturedException.Throw();
}
}
}
示例6: btnSearch_Click
private async void btnSearch_Click(object sender, EventArgs e)
{
App.speechRecognizerWithUI.Settings.ExampleText = "salad";
App.speechRecognizerWithUI.Settings.ShowConfirmation = true;
App.speechRecognizerWithUI.Settings.ListenText = "What are you looking for?";
var result = await App.speechRecognizerWithUI.RecognizeWithUIAsync();
if (result.ResultStatus == Windows.Phone.Speech.Recognition.SpeechRecognitionUIStatus.Succeeded)
{
SpeechSynthesizer synth = new SpeechSynthesizer();
if (result.RecognitionResult.TextConfidence == Windows.Phone.Speech.Recognition.SpeechRecognitionConfidence.High ||
result.RecognitionResult.TextConfidence == Windows.Phone.Speech.Recognition.SpeechRecognitionConfidence.Medium)
{
var recipe = App.Recipes.FindRecipeByText(result.RecognitionResult.Text);
if (null != recipe)
NavigationService.Navigate(new Uri("/RecipeDetailPage.xaml?ID=" + recipe.UniqueId, UriKind.Relative));
else
await synth.SpeakTextAsync(string.Format("Cannot find any {0}. I am sorry!"), result.RecognitionResult.Text);
}
else
{
await synth.SpeakTextAsync("I am not sure what you just said. Please try again!");
}
}
}
示例7: SpeakNotifications
private async void SpeakNotifications()
{
SpeechSynthesizer synth = new SpeechSynthesizer();
StringBuilder sb = new StringBuilder();
if (Tweets.Count == 0)
{
await synth.SpeakTextAsync(Resources.NoNewNotifications);
return;
}
foreach (var tweet in Tweets)
sb.AppendLine(TweetToText(tweet));
await synth.SpeakTextAsync(sb.ToString());
}
示例8: SelectSynthVoice
private async void SelectSynthVoice(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (e.AddedItems != null && e.AddedItems.Count != 0)
{
_speechSynth = new SpeechSynthesizer();
_speechSynth.SetVoice((VoiceInformation)e.AddedItems[0]);
await _speechSynth.SpeakTextAsync(TextToSpeechBox.Text);
}
}
示例9: Leer_Click
private void Leer_Click(object sender, RoutedEventArgs e)
{
var synth = new SpeechSynthesizer();
var voices = InstalledVoices.All.Where(v => v.Language == "es-ES").OrderByDescending(v => v.Gender);
synth.SetVoice(voices.FirstOrDefault(v => v.Gender == VoiceGender.Male));
_task = synth.SpeakTextAsync("Esto es una prueba. Realmente dura mucho más de lo necesario. Si quieres puedes parar pulsando el botón Parar Voz");
}
示例10: ReadAloudWithOptions_Click
private async void ReadAloudWithOptions_Click(object sender, RoutedEventArgs e)
{
var sync = new SpeechSynthesizer();
// als Sprache eine männliche, deutsche Stimme von den installierten Sprachen abrufen und setzen
var voice = InstalledVoices.All.FirstOrDefault(v => v.Language == "de-DE" && v.Gender == VoiceGender.Male);
sync.SetVoice(voice);
// auf Ende des Vorlesevorganges warten
await sync.SpeakTextAsync(TextToRead.Text);
}
示例11: let_sSpeak
/*//*/
/// <summary>
/// When the user clicks on the button "let_sRead", the device reads the content of "text_read".
/// </summary>
/// <param name="sender">Don't know!</param>
/// <param name="e">Don't know!</param>
private async void let_sSpeak(/*object sender, RoutedEventArgs e*/)
{
if (toSay != null || toSay != "")
{
SpeechSynthesizer synth = new SpeechSynthesizer();
await synth.SpeakTextAsync(toSay);
}
}
示例12: Speak
/// <summary>
///
/// </summary>
/// <param name="text"></param>
public async void Speak(string text)
{
var voices = from v in InstalledVoices.All
where v.Language == MainPage.lanEn
select v;
var speech = new SpeechSynthesizer();
speech.SetVoice(voices.ElementAt(0));
await speech.SpeakTextAsync(text);
}
示例13: ReadOutLoud
public async void ReadOutLoud()
{
IEnumerable<VoiceInformation> voices = from voice in InstalledVoices.All
where voice.Language == "en-US" && voice.Gender == VoiceGender.Female
select voice;
// Set the voice as identified by the query.
//try
//{
// if(voices.Count() > 0)
// synth.SetVoice(voices.ElementAt(0));
//}
//catch
//{
//}
ICategoryRepository categoryRepository = new XmlCategoryRepository();
foreach (string id in categoryIds)
{
CategoryData category = categoryRepository.GetCategoryById(Convert.ToInt32(id));
//this.CategoryName.Text = category.Name;
Uri imageUri = new Uri(category.Image, UriKind.Relative);
var bitmap = new BitmapImage(imageUri);
this.CategoryImage.Source = bitmap;
RssParser rssParser = new RssParser();
Uri feedUri = new Uri(category.Feed, UriKind.Relative);
StreamResourceInfo sri = Application.GetResourceStream(feedUri);
rssParser.initializeLocal(sri.Stream);
List<NewsItem> topStories = rssParser.getTopStories();
foreach (NewsItem newsItem in topStories)
{
try
{
synth = new SpeechSynthesizer();
if (voices.Count() > 0)
synth.SetVoice(voices.ElementAt(0));
if (String.IsNullOrEmpty(newsItem.description))
continue;
this.CategoryName.Text = newsItem.title;
this.SummaryBlock.Text = newsItem.description;
string textToRead = newsItem.title + ".\n" + newsItem.source + " reports, " + newsItem.description + "\n\n";
await synth.SpeakTextAsync(textToRead);
synth.Dispose();
}
catch
{
}
}
}
}
示例14: Say
public async Task Say(string text, string filterLanguage = null)
{
// Query for a voice that speaks French.
filterLanguage = filterLanguage ?? Languages.esES;
IEnumerable<VoiceInformation> voices = from voice in InstalledVoices.All
where voice.Language == filterLanguage
select voice;
// Set the voice as identified by the query.
SpeechSynthesizer synth = new SpeechSynthesizer();
synth.SetVoice(voices.ElementAt(0));
await synth.SpeakTextAsync(text);
}
示例15: TextToSpeech
public async void TextToSpeech(string text)
{
if (!string.IsNullOrEmpty(text))
{
var synth = new SpeechSynthesizer();
IOrderedEnumerable<VoiceInformation> voices =
InstalledVoices.All.Where(v => v.Language == "es-ES").OrderByDescending(v => v.Gender);
const VoiceGender gender = VoiceGender.Female;
synth.SetVoice(voices.FirstOrDefault(v => v.Gender == gender));
await synth.SpeakTextAsync(text);
}
}