本文整理汇总了C#中SpeechSynthesizer.SelectVoice方法的典型用法代码示例。如果您正苦于以下问题:C# SpeechSynthesizer.SelectVoice方法的具体用法?C# SpeechSynthesizer.SelectVoice怎么用?C# SpeechSynthesizer.SelectVoice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpeechSynthesizer
的用法示例。
在下文中一共展示了SpeechSynthesizer.SelectVoice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SpeechToWavBytes
/// <summary>
/// See interface docs.
/// </summary>
/// <param name="speechText"></param>
/// <returns></returns>
public byte[] SpeechToWavBytes(string speechText)
{
if(speechText == null) throw new ArgumentNullException("speechText");
byte[] result = new byte[] {};
if(IsSupported) {
using(MemoryStream memoryStream = new MemoryStream()) {
using(SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer() { Rate = -3 }) {
var configuration = Factory.Singleton.Resolve<IConfigurationStorage>().Singleton.Load();
speechSynthesizer.Rate = configuration.AudioSettings.VoiceRate;
string defaultVoice = speechSynthesizer.Voice.Name;
try {
speechSynthesizer.SelectVoice(configuration.AudioSettings.VoiceName);
} catch(Exception ex) {
Debug.WriteLine(String.Format("Audio.SpeechToWavBytes caught exception {0}", ex.ToString()));
speechSynthesizer.SelectVoice(defaultVoice);
}
speechSynthesizer.SetOutputToWaveStream(memoryStream);
speechSynthesizer.Speak(speechText);
}
memoryStream.Flush();
result = memoryStream.ToArray();
}
}
return result;
}
示例2: Speaker
public Speaker(Language lang = Language.English)
{
this.lang = lang;
AsyncMode = false; // Default to synchron speech
UseSSML = false; // Default to non-SSML speech
try
{
// Create synthesizer
ss = new SpeechSynthesizer();
ss.SetOutputToDefaultAudioDevice();
// Select language
if (!UseSSML)
{
switch (lang)
{
case Language.English: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-GB, Hazel)"); break;
case Language.Finish: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (fi-FI, Heidi)"); break;
case Language.Norwegian: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (nb-NO, Hulda)"); break;
case Language.Russian: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (ru-RU, Elena)"); break;
case Language.Swedish: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (sv-SE, Hedvig)"); break;
default: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-GB, Hazel)"); break;
}
}
}
catch (Exception e)
{
Console.WriteLine("An error occured: '{0}'", e);
}
}
示例3: initVoice
/// <summary>
/// Initiate the SpeechSynthesizer.
/// </summary>
/// <returns></returns>
public static SpeechSynthesizer initVoice()
{
synth = new SpeechSynthesizer();
synth.SetOutputToDefaultAudioDevice();
synth.SelectVoice(voiceName);
return synth;
}
示例4: SpeakService
private SpeakService()
{
_synthesizer = new SpeechSynthesizer();
_synthesizer.SelectVoice(VoiceName);
Repeat = true;
}
示例5: SpeechSynchrone
// Méthode permettant de lancer la synchronisation de maniere synchrone
//
public static void SpeechSynchrone(String text)
{
SpeechSynthesizer s = new SpeechSynthesizer();
String voix = "ScanSoft Virginie_Dri40_16kHz";
s.SelectVoice(voix);
s.Speak(text);
}
示例6: VoiceCanBeHeard
public void VoiceCanBeHeard() {
var synth = new SpeechSynthesizer();
synth.SelectVoice("Microsoft Hazel Desktop");
synth.Speak("This is an example of what to do");
synth.Speak(NumberUtilities.Direction.Ascending.ToString());
}
示例7: ConfigureVoice
public static bool ConfigureVoice(SpeechSynthesizer synth, string name, int speed, int volume, bool defaultOutput, int customOutput)
{
try
{
synth.SetOutputToDefaultAudioDevice();
if (!defaultOutput)
{
HackCustomDevice(synth, customOutput);
// do stuff.
}
}
catch
{
}
if (string.IsNullOrEmpty(name))
name = initialName;
try
{
if (!string.IsNullOrEmpty(name))
synth.SelectVoice(name);
}
catch
{
return false;
}
synth.Rate = speed;
synth.Volume = volume;
return true;
}
示例8: load_listen
public void load_listen(VI_Profile profile, VI_Settings settings, ListView statusContainer)
{
this.profile = profile;
this.settings = settings;
this.statusContainer = statusContainer;
vi_syn = profile.synth;
vi_syn.SelectVoice(settings.voice_info);
vi_sre = new SpeechRecognitionEngine(settings.recognizer_info);
GrammarBuilder phrases_grammar = new GrammarBuilder();
List<string> glossory = new List<string>();
foreach (VI_Phrase trigger in profile.Profile_Triggers)
{
glossory.Add(trigger.value);
}
if (glossory.Count == 0)
{
MessageBox.Show("You need to add at least one Trigger");
return;
}
phrases_grammar.Append(new Choices(glossory.ToArray()));
vi_sre.LoadGrammar(new Grammar(phrases_grammar));
//set event function
vi_sre.SpeechRecognized += phraseRecognized;
vi_sre.SpeechRecognitionRejected += _recognizer_SpeechRecognitionRejected;
vi_sre.SetInputToDefaultAudioDevice();
vi_sre.RecognizeAsync(RecognizeMode.Multiple);
}
示例9: Main
static void Main(string[] args)
{
string voiceFileName = args[0];
string voiceFileNamemp3 = voiceFileName.Replace(".wav", ".mp3");
string voiceFilePath = args[1];
string toBeVoiced = args[2];
int rate = int.Parse(args[3]); ;
string voice = args[4];
voiceFileName = voiceFileName.Replace("~", " ");
voiceFilePath = voiceFilePath.Replace("~", " ");
toBeVoiced = toBeVoiced.Replace("~", " ");
voice = voice.Replace("~", " ");
var reader = new SpeechSynthesizer();
reader.Rate = rate;
reader.SelectVoice(voice);
try
{
reader.SetOutputToWaveFile(voiceFilePath + voiceFileName, new SpeechAudioFormatInfo(16025, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
reader.Speak(toBeVoiced);
reader.Dispose();
WaveToMP3(voiceFilePath + voiceFileName, voiceFilePath + voiceFileNamemp3);
}
catch (Exception er)
{
string s1 = er.Message;
}
}
示例10: TestButton_Click
private void TestButton_Click(object sender, EventArgs e)
{
SpeechSynthesizer synth = new SpeechSynthesizer();
synth.SelectVoice(_settings.CurrentTTSVoice.VoiceInfo.Name);
synth.Rate = _settings.TTS_Rate;
synth.SpeakAsync("This is " + _settings.CurrentTTSVoice.VoiceInfo.Description + " Speaking at a rate of " + _settings.TTS_Rate);
}
示例11: Run
public void Run()
{
using (SpeechSynthesizer speaker = new SpeechSynthesizer()) {
speaker.SelectVoice(VoiceName);
speaker.Rate = Rate;
speaker.Speak(Text);
}
}
示例12: AIModule
public AIModule()
{
iTunes = new iTunesLib.iTunesApp();
bot = new SpeechSynthesizer();
bot.SelectVoice("VW Paul");
bot.Rate = 1;
bot.Volume = 100;
}
示例13: Speech
public Speech()
{
sr = new SpeechRecognitionEngine();
ss = new SpeechSynthesizer();
sr.SetInputToDefaultAudioDevice();
ss.SelectVoice("Microsoft Anna");
ss.SetOutputToDefaultAudioDevice();
}
示例14: Play
public void Play()
{
speaker = new SpeechSynthesizer();
speaker.SelectVoice("ScanSoft Raquel_Full_22kHz");
speaker.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(speaker_SpeakCompleted);
speaker.SpeakAsync(texto);
speaker.Resume();
}
示例15: Speak
public string Speak(string sText, bool bToFile)
{
SpeechSynthesizer oSpeaker = new SpeechSynthesizer();
oSpeaker.Rate = 1;
oSpeaker.SelectVoice("Microsoft Anna");
oSpeaker.Volume = 100;
if (bToFile)
{
oSpeaker.SetOutputToWaveFile("SoundByte.wav");
}
oSpeaker.Speak(sText);
string msg;
// Initialize a new instance of the SpeechSynthesizer.
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
// Get information about supported audio formats.
string AudioFormats = "";
foreach (SpeechAudioFormatInfo fmt in synth.Voice.SupportedAudioFormats)
{
AudioFormats += String.Format("{0}\n",
fmt.EncodingFormat.ToString());
}
// Write information about the voice to the console.
msg = "Name: " + synth.Voice.Name + "\n";
msg += "Culture: " + synth.Voice.Culture + "\n";
msg += " Age: " + synth.Voice.Age + "\n";
msg += " Gender: " + synth.Voice.Gender + "\n";
msg += " Description: " + synth.Voice.Description + "\n";
msg += " ID: " + synth.Voice.Id + "\n";
if (synth.Voice.SupportedAudioFormats.Count != 0)
{
msg += " Audio formats: " + AudioFormats + "\n";
}
else
{
msg += " No supported audio formats found" + "\n";
}
// Get additional information about the voice.
foreach (string key in synth.Voice.AdditionalInfo.Keys)
{
msg += String.Format(" {0}: {1}\n",key, synth.Voice.AdditionalInfo[key]);
}
msg += " Additional Info - ";
}
oSpeaker.Dispose();
oSpeaker = null;
return msg;
}