mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-03 09:03:42 -04:00
Herald v2 (#74)
* Add speech rate setting * Add volume slider * New speech manager skeleton * User API key from resx * Implement voice list retrieve via new api * Rewrite to use ObAPI, remove all dependancies * Use volume setting * Clean up using statements * Volume and timing adjustments * Lookup rate value * Use numeric rates for tighter spread * Manage plugin data folder via core interface * Add check that nullable settings are not null. * Get file size before it's deleted. * Improve old settings migration. * Ignore cache sizes below 1MB * Re-index orphaned files in cache, purge legacy wav files. * Call top level error logging for native voice exception. * Async title and detail requests to remove pause * Remove NetCoreAudio use of temp files. * Remove orphan using.
This commit is contained in:
98
ObservatoryHerald/NetCoreAudio/Player.cs
Normal file
98
ObservatoryHerald/NetCoreAudio/Player.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using NetCoreAudio.Interfaces;
|
||||
using NetCoreAudio.Players;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NetCoreAudio
|
||||
{
|
||||
public class Player : IPlayer
|
||||
{
|
||||
private readonly IPlayer _internalPlayer;
|
||||
|
||||
/// <summary>
|
||||
/// Internally, sets Playing flag to false. Additional handlers can be attached to it to handle any custom logic.
|
||||
/// </summary>
|
||||
public event EventHandler PlaybackFinished;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the audio is currently playing.
|
||||
/// </summary>
|
||||
public bool Playing => _internalPlayer.Playing;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the audio playback is currently paused.
|
||||
/// </summary>
|
||||
public bool Paused => _internalPlayer.Paused;
|
||||
|
||||
public Player()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
_internalPlayer = new WindowsPlayer();
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
_internalPlayer = new LinuxPlayer();
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
_internalPlayer = new MacPlayer();
|
||||
else
|
||||
throw new Exception("No implementation exist for the current OS");
|
||||
|
||||
_internalPlayer.PlaybackFinished += OnPlaybackFinished;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will stop any current playback and will start playing the specified audio file. The fileName parameter can be an absolute path or a path relative to the directory where the library is located. Sets Playing flag to true. Sets Paused flag to false.
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Play(string fileName)
|
||||
{
|
||||
await _internalPlayer.Play(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pauses any ongong playback. Sets Paused flag to true. Doesn't modify Playing flag.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task Pause()
|
||||
{
|
||||
await _internalPlayer.Pause();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resumes any paused playback. Sets Paused flag to false. Doesn't modify Playing flag.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task Resume()
|
||||
{
|
||||
await _internalPlayer.Resume();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops any current playback and clears the buffer. Sets Playing and Paused flags to false.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task Stop()
|
||||
{
|
||||
await _internalPlayer.Stop();
|
||||
}
|
||||
|
||||
private void OnPlaybackFinished(object sender, EventArgs e)
|
||||
{
|
||||
PlaybackFinished?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the playing volume as percent
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task SetVolume(byte percent)
|
||||
{
|
||||
await _internalPlayer.SetVolume(percent);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_internalPlayer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user