mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-12-17 21:14:58 +01:00
observatory herald (#30)
* WIP: initial commit for observatory herald * Plugin error handling refactor * make error window non-modal * tidy up plugin error handling * first pass for basic herald functionality * corrections for linux env * Use FNV hash directly instead of managing through dictionary/index file * resolve audio queuing issue, switch to personal NetCoreAudio fork * merge cleanup * add enable setting, populate defaults * framework xml doc update * Adjust settings, add style selection, replace locale with demonym in dropdown list. * Test is position is on screen before saving/loading. * use a default that's actually in the list
This commit is contained in:
77
ObservatoryHerald/HeraldNotifier.cs
Normal file
77
ObservatoryHerald/HeraldNotifier.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Microsoft.CognitiveServices.Speech;
|
||||
using Observatory.Framework;
|
||||
using Observatory.Framework.Interfaces;
|
||||
using System;
|
||||
|
||||
namespace Observatory.Herald
|
||||
{
|
||||
public class HeraldNotifier : IObservatoryNotifier
|
||||
{
|
||||
public HeraldNotifier()
|
||||
{
|
||||
heraldSettings = new()
|
||||
{
|
||||
SelectedVoice = "American - Christopher",
|
||||
AzureAPIKeyOverride = string.Empty,
|
||||
Enabled = true
|
||||
};
|
||||
}
|
||||
|
||||
public string Name => "Observatory Herald";
|
||||
|
||||
public string ShortName => "Herald";
|
||||
|
||||
public string Version => typeof(HeraldNotifier).Assembly.GetName().Version.ToString();
|
||||
|
||||
public PluginUI PluginUI => new (PluginUI.UIType.None, null);
|
||||
|
||||
public object Settings { get => heraldSettings; set => heraldSettings = (HeraldSettings)value; }
|
||||
|
||||
public void Load(IObservatoryCore observatoryCore)
|
||||
{
|
||||
var azureManager = new VoiceSpeechManager(heraldSettings, observatoryCore.HttpClient);
|
||||
heraldSpeech = new HeraldQueue(azureManager);
|
||||
heraldSettings.Test = TestVoice;
|
||||
}
|
||||
|
||||
private void TestVoice()
|
||||
{
|
||||
heraldSpeech.Enqueue(
|
||||
new NotificationArgs()
|
||||
{
|
||||
Title = "Herald voice testing",
|
||||
Detail = $"This is {heraldSettings.SelectedVoice.Split(" - ")[1]}."
|
||||
},
|
||||
GetAzureNameFromSetting(heraldSettings.SelectedVoice),
|
||||
GetAzureStyleNameFromSetting(heraldSettings.SelectedVoice));
|
||||
}
|
||||
|
||||
public void OnNotificationEvent(NotificationArgs notificationEventArgs)
|
||||
{
|
||||
if (heraldSettings.Enabled)
|
||||
heraldSpeech.Enqueue(
|
||||
notificationEventArgs,
|
||||
GetAzureNameFromSetting(heraldSettings.SelectedVoice),
|
||||
GetAzureStyleNameFromSetting(heraldSettings.SelectedVoice));
|
||||
}
|
||||
|
||||
private string GetAzureNameFromSetting(string settingName)
|
||||
{
|
||||
var voiceInfo = (VoiceInfo)heraldSettings.Voices[settingName];
|
||||
return voiceInfo.Name;
|
||||
}
|
||||
|
||||
private string GetAzureStyleNameFromSetting(string settingName)
|
||||
{
|
||||
string[] settingParts = settingName.Split(" - ");
|
||||
|
||||
if (settingParts.Length == 3)
|
||||
return settingParts[2];
|
||||
else
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private HeraldSettings heraldSettings;
|
||||
private HeraldQueue heraldSpeech;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user