/// <summary> /// /// </summary> /// <param name="slide"></param> /// <param name="captionText"></param> /// <param name="tagNo"></param> /// <param name="voiceLabel">Format "voiceName(_Default)"</param> /// <returns></returns> private static Shape InsertAudioShapeToSlide(PowerPointSlide slide, string captionText, int tagNo, string voiceLabel) { if (string.IsNullOrEmpty(captionText.Trim())) { return(null); } string shapeName = string.Format(ELearningLabText.AudioCustomShapeNameFormat, tagNo, voiceLabel); if (!Directory.Exists(Path.Combine(Path.GetTempPath(), TempFolderName))) { Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), TempFolderName)); } string audioFilePath = Path.Combine(Path.GetTempPath(), TempFolderName, string.Format(ELearningLabText.AudioFileNameFormat, slide.ID, tagNo)); string voiceName = StringUtility.ExtractVoiceNameFromVoiceLabel(voiceLabel); IVoice voice = GetVoiceFromString(voiceName); Shape shape = null; bool isSavedSuccessful = false; bool isSameCaptionText = IsSameCaptionText(slide, captionText, voiceLabel, tagNo); if (!isSameCaptionText) { isSavedSuccessful = SaveTextToWaveFile(captionText, audioFilePath, voice); } if (isSameCaptionText || isSavedSuccessful) { shape = InsertAudioFileOnSlide(slide, audioFilePath); } if (shape != null) { shape.Name = shapeName; } return(shape); }
public static bool IsWatsonVoiceSelectedForItem(ExplanationItem selfExplanationClickItem) { string voiceName = StringUtility.ExtractVoiceNameFromVoiceLabel(selfExplanationClickItem.VoiceLabel); IVoice voice = GetVoiceFromString(voiceName); return(voice is WatsonVoice); }
public BakedTTS BakeTTS(IVoice voice, string text, double rate, int pitch) { if(voice.ParentEngine != this) throw new Exception("not parent engine"); return BuildTTS(voice, text, rate, pitch); }
public TextToSpeech4(ISpeechModule speechModule) { // Do Component speechModule.Add(this); _speechModule = speechModule; _speechModule.TextToSpeech = this; // Initialize Voice voice4 = new HTTSLib.TextToSpeech(); voice4.Select(1); voice4.Speed = 156; voice4.Visual += Voice4_Visual; _phonemes = Speech.Phonemes.GetPhonemesSapi4(); // Get Voices _current = new Tts4Voice { Gender = (Gender)voice4.Gender(1), Name = voice4.Speaker(1) }; // Turn off Listener events //_speechModule.IsSpeaking = false; // Write Debug Log _speechModule.LanguageModel.AI.Engine.Debugger.Log(DebuggerLogLevel.Log, Resources.TTS_Initialized); }
protected override BakedTTS BuildTTS(IVoice voice, string text, double rate, int pitch) { var _voice = ((SystemVoice)voice)._voice; List <VisemeSpan> visemes = new List <VisemeSpan>(); EventHandler <VisemeReachedEventArgs> visemeHandler = (o, args) => { var v = IntToViseme(args.Viseme); var d = args.Duration.TotalSeconds; visemes.Add(new VisemeSpan() { viseme = v, duration = d }); }; using (var m = new MemoryStream()) { _synthesizer.VisemeReached += visemeHandler; UpdateSpeechData(_voice, text, rate, pitch); _synthesizer.SetOutputToWaveStream(m); _synthesizer.Speak(_builder); _synthesizer.SetOutputToDefaultAudioDevice(); _synthesizer.VisemeReached -= visemeHandler; return(visemes.Count == 0 ? null : new BakedTTS() { waveStreamData = m.ToArray(), visemes = visemes.ToArray() }); } }
private static void OnSettingsDialogConfirmed(VoiceType selectedVoiceType, IVoice selectedVoice, bool isPreviewCurrentSlide) { IsPreviewEnabled = isPreviewCurrentSlide; AudioSettingService.selectedVoiceType = selectedVoiceType; AudioSettingService.selectedVoice = selectedVoice; }
public void SetAudioMainSettings(VoiceType selectedVoiceType, IVoice selectedVoice, bool isPreviewChecked) { computerVoiceComboBox.ToolTip = NarrationsLabText.SettingsVoiceSelectionInputTooltip; previewCheckbox.IsChecked = isPreviewChecked; previewCheckbox.ToolTip = NarrationsLabText.SettingsPreviewCheckboxTooltip; switch (selectedVoiceType) { case VoiceType.AzureVoice: RadioAzureVoice.IsChecked = true; azureVoiceComboBox.SelectedItem = selectedVoice as AzureVoice; break; case VoiceType.ComputerVoice: RadioDefaultVoice.IsChecked = true; computerVoiceComboBox.SelectedItem = selectedVoice as ComputerVoice; break; case VoiceType.WatsonVoice: RadioWatsonVoice.IsChecked = true; watsonVoiceComboBox.SelectedItem = selectedVoice as WatsonVoice; break; default: break; } }
public void Dispose() { updateHandler.RemoveObserver(this); voice.Frequency = 0f; song = null; voice = null; maker = null; }
private static List <string> ConvertAudioPreferencesToList() { IVoice defaultVoice = AudioSettingService.selectedVoice; List <string> voices = AudioSettingService.preferredVoices.ToList().Select(x => x.VoiceName).ToList(); voices.Insert(0, defaultVoice.ToString()); return(voices); }
public void SetVoice(IVoice voice) { SelectedVoice = voice; Settings.Default.LastVoice = SelectedVoice.Name; Settings.Default.Save(); OnPropertyChanged(nameof(SelectedVoice)); }
public Task <Stream> SynthesizeTextToStreamAsync(IVoice voice, string text) { var result = Service.Synthesize(new Text() { _Text = text }, "audio/mp3", voice.Name); return(Task.FromResult((Stream)result)); }
public BakedTTS BakeTTS(IVoice voice, string text, double rate, int pitch) { if (voice.ParentEngine != this) { throw new Exception("not parent engine"); } return(BuildTTS(voice, text, rate, pitch)); }
static void Main(string[] args) { IFavoriteFood food = new QITest(); food.Food(); IVoice voice = food as IVoice; voice.Voice(); Console.ReadLine(); }
public VoiceValue(UpdateHandler updateHandler, int voiceNum, ISoundMaker maker) { this.voiceNum = voiceNum; this.maker = maker; this.updateHandler = updateHandler; voice = maker.GetVoice(voiceNum); maker.SetWave(voiceNum, "square"); this.updateHandler.AddObserver(this); InitalizeSuffixes(); }
public async Task <Stream> SynthesizeTextToStreamAsync(IVoice voice, string text) { return(await Task.Run <Stream>(() => { using (var synth = new SpeechSynthesizer()) { synth.SelectVoice(voice.Name); var stream = new MemoryStream(); synth.SetOutputToWaveStream(stream); synth.Speak(text); return stream; } })); }
public async Task <Stream> SynthesizeTextToStreamAsync(IVoice voice, string text) { var pollyVoice = (AmazonPollyVoice)voice; var request = new SynthesizeSpeechRequest() { Text = text, VoiceId = VoiceId.FindValue(pollyVoice.VoiceId), OutputFormat = OutputFormat.Mp3 }; var response = await _client.SynthesizeSpeechAsync(request); return(response.AudioStream); }
/// <summary> /// Constructor of the singleton class. /// </summary> private VoiceManager() { _nexmoInstance = new NexmoApi(); _twilioInstance = new TwilioApi(); string apiHierarchy = ConfigurationManager.AppSettings[NeeoConstants.VoiceApiHierarchy]; if (string.IsNullOrWhiteSpace(apiHierarchy)) { _primaryApi = _nexmoInstance; _secondaryApi = _twilioInstance; } else { string[] apiList = apiHierarchy.Split(new string[] { "-" }, 2, StringSplitOptions.RemoveEmptyEntries); if (apiList.Length == 2) { if (apiList[0] == "nexmo") { _primaryApi = _nexmoInstance; } if (apiList[0] == "twilio") { _primaryApi = _twilioInstance; } if (apiList[1] == "nexmo") { _secondaryApi = _nexmoInstance; } if (apiList[1] == "twilio") { _secondaryApi = _twilioInstance; } } else { _primaryApi = _nexmoInstance; _secondaryApi = _twilioInstance; } } _successorApi = _primaryApi; _primaryApi.SuccessorApi = _secondaryApi; }
public async Task <Stream> SynthesizeTextToStreamAsync(IVoice voice, string text) { using (var synth = new SpeechSynthesizer()) { synth.Voice = SpeechSynthesizer.AllVoices.First(info => info.DisplayName == voice.Name); var synthStream = await synth.SynthesizeTextToStreamAsync(text); using (var reader = new DataReader(synthStream)) { await reader.LoadAsync((uint)synthStream.Size); var buffer = reader.ReadBuffer((uint)synthStream.Size); var stream = buffer.AsStream(); return(stream); } } }
private void ConfigureAudioPreviewSettings(AudioPreviewPage page) { string textToSpeak = captionTextBox.Text.Trim(); string voiceName = StringUtility.ExtractVoiceNameFromVoiceLabel(audioNameLabel.Text.ToString()); if (!AudioService.CheckIfVoiceExists(voiceName)) { page.SetAudioPreviewSettings(textToSpeak, VoiceType.DefaultVoice, AudioSettingService.selectedVoice); return; } string defaultPostfix = StringUtility.ExtractDefaultLabelFromVoiceLabel(audioNameLabel.Text.ToString()); VoiceType voiceType = AudioService.GetVoiceTypeFromString(voiceName, defaultPostfix); IVoice voice = AudioService.GetVoiceFromString(voiceName); page.SetAudioPreviewSettings(textToSpeak, voiceType, voice); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { IVoice voice = value as IVoice; if (voice is ComputerVoice) { return(true); } else if (voice is WatsonVoice) { return(WatsonRuntimeService.IsWatsonAccountPresentAndValid); } else { return(AzureRuntimeService.IsAzureAccountPresentAndValid); } }
public TextToSpeechForm(DialogueStateActionDTO[] agentActions) { InitializeComponent(); _agentActions = agentActions; _dialogOptions.DataSource = _agentActions.Select(a => a.Utterance).ToArray(); _dialogOptions.SelectedIndex = -1; _availableVoices = _ttsEngines.SelectMany(e => e.GetAvailableVoices()).ToArray(); _voiceComboBox.DataSource = _availableVoices.Select(VoiceToIdString).ToArray(); _selectedVoice = _availableVoices[0]; UpdateButtonText(true); UpdateRateLabel(); UpdatePitchLabel(); SetVisemeDisplay(Viseme.Silence); }
private static bool SaveTextToWaveFile(string text, string filePath, IVoice voice) { if (voice is AzureVoice) { return(AzureRuntimeService.SaveStringToWaveFileWithAzureVoice(text, filePath, voice as AzureVoice)); } else if (voice is ComputerVoice) { ComputerVoiceRuntimeService.SaveStringToWaveFile(text, filePath, voice as ComputerVoice); return(true); } else if (voice is WatsonVoice) { WatsonRuntimeService.SaveStringToWaveFile(text, filePath, voice as WatsonVoice); return(true); } return(false); }
static void Main(string[] args) { Animal[] animalArr = new Animal[3]; animalArr[0] = new Cat(); animalArr[1] = new Dog(); animalArr[2] = new Shark(); foreach (Animal a in animalArr) { IVoice voice = a as IVoice; if (voice != null) { Console.WriteLine(voice.Voice()); } else { Console.WriteLine("No Voice"); } } }
private void SpeakButton_Click(object sender, RoutedEventArgs e) { string textToSpeak = spokenText.Text.Trim(); if (string.IsNullOrEmpty(textToSpeak)) { return; } IVoice voice = ((Button)sender).CommandParameter as IVoice; if (voice == null) { voice = SelectedVoice; } if (voice is ComputerVoice) { ComputerVoiceRuntimeService.SpeakString(textToSpeak, voice as ComputerVoice); } else if (voice is AzureVoice && !IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName)) { AzureRuntimeService.SpeakString(textToSpeak, voice as AzureVoice); } else if (voice is AzureVoice && IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName)) { string dirPath = System.IO.Path.GetTempPath() + AudioService.TempFolderName; string filePath = dirPath + "\\" + string.Format(ELearningLabText.AudioPreviewFileNameFormat, voice.VoiceName); AzureRuntimeService.PlaySavedAudioForPreview(filePath); } else if (voice is WatsonVoice && !IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName)) { WatsonRuntimeService.Speak(textToSpeak, voice as WatsonVoice); } else if (voice is WatsonVoice && IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName)) { string dirPath = System.IO.Path.GetTempPath() + AudioService.TempFolderName; string filePath = dirPath + "\\" + string.Format(ELearningLabText.AudioPreviewFileNameFormat, voice.VoiceName); AzureRuntimeService.PlaySavedAudioForPreview(filePath); } }
/// <summary> /// Constructs a new brain object. /// </summary> /// <param name="visionPreview">A capture element that is placed on a canvas used for capturing what Robbie sees.</param> /// <param name="previewCanvas">A canvas element used for rendering the image preview showing what Robbie sees.</param> /// <param name="audioPlaybackElement">A media element that is placed on a canvas used for speaking.</param> public Brain(CaptureElement visionPreview, Canvas previewCanvas, MediaElement audioPlaybackElement) { utterancePrediction = new UtterancePrediction(); ears = new Ears(); voice = new Voice(audioPlaybackElement); eyes = new Eyes(visionPreview, previewCanvas); pool = new ClientConnectionPool(); currentIdentityPersonId = AnonymousPersonId; // define the event handlers for handling the different events occuring from all the senses ears.SpeechRecognized += Ears_SpeechRecognized; ears.EarsStateChanged += Ears_EarsStateChanged; voice.FinishedPlaybackEventHandler += Voice_FinishedPlayback; eyes.NewActivePersonEvent += Eyes_NewActivePersonEvent; // always start in a sleeping state (not actively listening) sleeping = true; }
public static VoiceType GetVoiceTypeFromString(string voiceName, string defaultPostfix) { if (IsDefaultVoiceType(defaultPostfix)) { return(VoiceType.DefaultVoice); } IVoice voice = GetVoiceFromString(voiceName); if (voice is AzureVoice) { return(VoiceType.AzureVoice); } else if (voice is WatsonVoice) { return(VoiceType.WatsonVoice); } else { return(VoiceType.ComputerVoice); } }
private bool UpdateRankedAudioPreferences() { List <IVoice> voices = Voices.ToList().Where(x => x.Rank > 0).OrderBy(x => x.Rank).ToList(); ObservableCollection <IVoice> voicesRanked = new ObservableCollection <IVoice>(); for (int i = 0; i < voices.Count; i++) { IVoice voice = voices[i]; if (voice.Rank != i + 1) { MessageBox.Show("Please rank in sequence."); return(false); } } foreach (IVoice voice in voices) { voicesRanked.Add(voice); } AudioSettingService.preferredVoices = voicesRanked; return(true); }
public async Task <Stream> SynthesizeTextToStreamAsync(IVoice voice, string text) { var input = new SynthesisInput { Text = text }; var config = new AudioConfig { AudioEncoding = AudioEncoding.Mp3 }; var response = await Client.SynthesizeSpeechAsync(new SynthesizeSpeechRequest { Input = input, Voice = new VoiceSelectionParams() { Name = voice.Name, LanguageCode = voice.Language }, AudioConfig = config, }); return(new MemoryStream(response.AudioContent.ToByteArray())); }
protected override BakedTTS BuildTTS(IVoice voice, string text, double rate, int pitch) { var _voice = ((SystemVoice) voice)._voice; List<VisemeSpan> visemes = new List<VisemeSpan>(); EventHandler<VisemeReachedEventArgs> visemeHandler = (o, args) => { var v = IntToViseme(args.Viseme); var d = args.Duration.TotalSeconds; visemes.Add(new VisemeSpan() { viseme = v, duration = d }); }; using (var m = new MemoryStream()) { _synthesizer.VisemeReached += visemeHandler; UpdateSpeechData(_voice, text, rate, pitch); _synthesizer.SetOutputToWaveStream(m); _synthesizer.Speak(_builder); _synthesizer.SetOutputToDefaultAudioDevice(); _synthesizer.VisemeReached -= visemeHandler; return visemes.Count == 0 ? null : new BakedTTS() { waveStreamData = m.ToArray(), visemes = visemes.ToArray() }; } }
private static void InitializeDefaultAndRankedVoicesFromList(List <string> preferences) { AudioSettingService.preferredVoices.Clear(); for (int i = 0; i < preferences.Count(); i++) { string voiceName = preferences[i].Trim(); IVoice voice = AudioService.GetVoiceFromString(voiceName); voice.Rank = i; if (i == 0) { if (voice is ComputerVoice) { AudioSettingService.selectedVoiceType = VoiceType.ComputerVoice; AudioSettingService.selectedVoice = voice; } else if (voice is AzureVoice && AzureRuntimeService.IsAzureAccountPresentAndValid) { AudioSettingService.selectedVoiceType = VoiceType.AzureVoice; AudioSettingService.selectedVoice = voice; } else if (voice is WatsonVoice && WatsonRuntimeService.IsWatsonAccountPresentAndValid) { AudioSettingService.selectedVoiceType = VoiceType.WatsonVoice; AudioSettingService.selectedVoice = voice; } else { Logger.Log("Error: Voice retrieved has invalid type"); } } else { AudioSettingService.preferredVoices.Add(voice); } } }
private void OnVoiceSelectionChange(object sender, EventArgs e) { _selectedVoice = _availableVoices[_voiceComboBox.SelectedIndex]; }
private static string VoiceToIdString(IVoice info) { return($"{info.Name}, {info.Gender} - {info.Age}, {info.Culture} ({info.ParentEngine.Name})"); }
protected override BakedTTS BuildTTS(IVoice voice, string text, double rate, int pitch) { var tts = RequestTTS((L2FVoice)voice, text); if (tts == null) return null; //Create visemes List<VisemeSpan> visemes = new List<VisemeSpan>(); //Convert phones to visemes and adjust time to rate var mapper = LanguageResources.PT_PhonesToVisemes; Viseme lastViseme = Viseme.Silence; double totalVisemeTime = 0; foreach (var r in tts) { var phones = ((JsonArray)r["phones"]).Select(t => ((JsonString)t).String); var time = ((JsonArray) r["times"]).Select(t => Convert.ToDouble(((JsonNumber) t).Value)); var toProcess = phones.Zip(time, (s, d) => new { ph = s, entryTime = d }).ToArray(); totalVisemeTime += toProcess[0].entryTime;///rate; lastViseme = Viseme.Silence; for (int i = 1; i < toProcess.Length-1; i++) { var p = toProcess[i]; var nextTime = toProcess[i+1].entryTime; Viseme currentViseme; if (!mapper.TryGetValue(p.ph, out currentViseme)) currentViseme = Viseme.Silence; if (lastViseme != currentViseme) { visemes.Add(new VisemeSpan() { duration = totalVisemeTime/rate, viseme = lastViseme }); lastViseme = currentViseme; totalVisemeTime = 0; } var duration = nextTime - p.entryTime; totalVisemeTime += duration; } } if(totalVisemeTime>0) visemes.Add(new VisemeSpan() { duration = totalVisemeTime/rate, viseme = lastViseme }); if (visemes.Count == 0) return null; //Create audio var audioUrls = tts.Select(r => ((JsonString)r["url"]).String).ToArray(); var v = BuildAudioStream(audioUrls, rate, pitch); const int MAX_SAMPLES = 5120; var bufferSize = MAX_SAMPLES * v.WaveFormat.Channels; var buffer = new float[bufferSize]; using (var m = new MemoryStream()) { using (var w = new WaveFileWriter(m, v.WaveFormat)) { int readed; while ((readed = v.Read(buffer, 0, bufferSize)) > 0) { w.WriteSamples(buffer, 0, readed); } w.Flush(); return new BakedTTS() { visemes = visemes.ToArray(), waveStreamData = m.ToArray() }; } } }
public VoicePlayer BuildPlayer(IVoice voice, string text, double rate, int pitch) { var tts = BakeTTS(voice, text, rate, pitch); return tts == null ? null : new VoicePlayer(tts); }
protected abstract BakedTTS BuildTTS(IVoice voice, string text, double rate, int pitch);
public HelloApplication(IHello words, IVoice voice) { this.Words = words; this.Voice = voice; }