本文整理汇总了C#中SpeechSynthesizer.SetVoice方法的典型用法代码示例。如果您正苦于以下问题:C# SpeechSynthesizer.SetVoice方法的具体用法?C# SpeechSynthesizer.SetVoice怎么用?C# SpeechSynthesizer.SetVoice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpeechSynthesizer
的用法示例。
在下文中一共展示了SpeechSynthesizer.SetVoice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
}
}
示例3: CreateSpeech
static private SpeechSynthesizer CreateSpeech()
{
var speech = new SpeechSynthesizer();
var language = CultureInfo.CurrentCulture.ToString();
var voices = InstalledVoices.All.Where(v => v.Language == language).OrderByDescending(v => v.Gender);
speech.SetVoice(voices.FirstOrDefault(v => v.Gender == gender));
return speech;
}
示例4: 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);
}
}
示例5: 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");
}
示例6: 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);
}
示例7: 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);
}
示例8: 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
{
}
}
}
}
示例9: GetSpeechSynthesizer
private static SpeechSynthesizer GetSpeechSynthesizer()
{
var speechSynthesizer = new SpeechSynthesizer();
IEnumerable<VoiceInformation> enUSMaleVoices = from voice in InstalledVoices.All
where voice.Gender == VoiceGender.Male &&
voice.Language == "en-US"
select voice;
speechSynthesizer.SetVoice(enUSMaleVoices.ElementAt(0));
return speechSynthesizer;
}
示例10: 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);
}
示例11: 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);
}
}
示例12: PhrasesManager
public PhrasesManager()
{
PhraseEngine.PhraseInitilaze();
try
{
synth = new SpeechSynthesizer();
VoiceInformation voices = InstalledVoices
.All
.Where(x => x.Language == "en-US")
.FirstOrDefault();
if (voices != null)
synth.SetVoice(voices);
_phraseAutomat = new PhraseAutomat();
}
catch(Exception ex)
{
}
}
示例13: WordsManager
public WordsManager()
{
WordEngine.WordInitilaze();
try
{
synth = new SpeechSynthesizer();
VoiceInformation voices = InstalledVoices
.All
.Where(x => x.Language == "en-US")
.FirstOrDefault();
if (voices != null)
synth.SetVoice(voices);
_wordAutomat = new WordAutomat();
}
catch(Exception e)
{
}
}
示例14: TextToSpeech
/// <summary>
/// Converts a text into a speech and pronounces it.
/// </summary>
/// <param name="text">The text to be pronounced.</param>
public async void TextToSpeech(string text)
{
try
{
if (!string.IsNullOrEmpty(text))
{
var synth = new SpeechSynthesizer();
var language = CultureInfo.CurrentCulture.ToString();
var voices = InstalledVoices.All.Where(v => v.Language == language).OrderByDescending(v => v.Gender);
const VoiceGender gender = VoiceGender.Female;
synth.SetVoice(voices.FirstOrDefault(v => v.Gender == gender));
await synth.SpeakTextAsync(HtmlUtil.CleanHtml(text));
}
}
catch (Exception ex)
{
Debug.WriteLine("{0}{1}. {2}{3}", AppResources.SpeechError, text, AppResources.Error, ex.ToString());
}
}
示例15: Listen
private async void Listen()
{
if (!busy)
{
busy = true;
// Initialize the SpeechRecognizerUI object.
recoWithUI = new SpeechRecognizerUI();
// Query for a recognizer that recognizes French as spoken in France.
IEnumerable<SpeechRecognizerInformation> recognizers = from recognizerInfo in InstalledSpeechRecognizers.All
select recognizerInfo;
// Set the recognizer to the top entry in the query result.
recoWithUI.Recognizer.SetRecognizer(recognizers.ElementAt(0));
// Create a string array of French numbers.
string[] settings = (from MarketCat cat in listOfCats.ToList()
select cat.Title).ToArray();
// Create a list grammar from the string array and add it to the grammar set.
recoWithUI.Recognizer.Grammars.AddGrammarFromList("categories", settings);
string listenText = "";
string exampleText = "";
for (int i = 0; i < settings.Length; i++)
{
listenText += settings[i];
exampleText += " " + settings[i];
}
// Display text to prompt the user's input.
recoWithUI.Settings.ListenText = "Category Between: ";
recoWithUI.Settings.ReadoutEnabled = false;
// Give an example of ideal speech input.
recoWithUI.Settings.ExampleText = exampleText;
// Load the grammar set and start recognition.
SpeechRecognitionUIResult recoResult = await recoWithUI.RecognizeWithUIAsync();
string action = recoResult.RecognitionResult.Text;
SpeechSynthesizer ss = new SpeechSynthesizer();
VoiceInformation vi = InstalledVoices.All.Where(v => v.Language == "en-EN" && v.Gender == VoiceGender.Male).FirstOrDefault();
ss.SetVoice(vi);
await ss.SpeakTextAsync("I'm looking for " + action + "!");
MarketCat chooseCat = (from MarketCat cat in listOfCats.ToList()
where cat.Title == action
select cat).FirstOrDefault();
chooseAppsPreview = CreateAppsPreview(chooseCat);
CategorieTitle.Text = chooseCat.Title;
AppsPreviewContent.Children.Clear();
AppsPreviewContent.Children.Add(chooseAppsPreview);
chooseAppsPreview.load();
chooseAppsPreview.CompletedEvent+= (e, o) =>
{
sayAppName();
};
}
busy = false;
}