Using Serilog. Added partial OBS batch request support. Added update checking. Added more commands. Added enabled/disabled TTS voices. And more.
This commit is contained in:
@ -14,7 +14,7 @@ public class AudioPlaybackEngine : IDisposable
|
||||
{
|
||||
SampleRate = sampleRate;
|
||||
outputDevice = new WaveOutEvent();
|
||||
|
||||
|
||||
mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount));
|
||||
mixer.ReadFully = true;
|
||||
|
||||
@ -49,25 +49,41 @@ public class AudioPlaybackEngine : IDisposable
|
||||
AddMixerInput(new CachedWavProvider(sound));
|
||||
}
|
||||
|
||||
public ISampleProvider ConvertSound(IWaveProvider provider) {
|
||||
public ISampleProvider ConvertSound(IWaveProvider provider)
|
||||
{
|
||||
ISampleProvider? converted = null;
|
||||
if (provider.WaveFormat.Encoding == WaveFormatEncoding.Pcm) {
|
||||
if (provider.WaveFormat.BitsPerSample == 8) {
|
||||
if (provider.WaveFormat.Encoding == WaveFormatEncoding.Pcm)
|
||||
{
|
||||
if (provider.WaveFormat.BitsPerSample == 8)
|
||||
{
|
||||
converted = new Pcm8BitToSampleProvider(provider);
|
||||
} else if (provider.WaveFormat.BitsPerSample == 16) {
|
||||
}
|
||||
else if (provider.WaveFormat.BitsPerSample == 16)
|
||||
{
|
||||
converted = new Pcm16BitToSampleProvider(provider);
|
||||
} else if (provider.WaveFormat.BitsPerSample == 24) {
|
||||
}
|
||||
else if (provider.WaveFormat.BitsPerSample == 24)
|
||||
{
|
||||
converted = new Pcm24BitToSampleProvider(provider);
|
||||
} else if (provider.WaveFormat.BitsPerSample == 32) {
|
||||
}
|
||||
else if (provider.WaveFormat.BitsPerSample == 32)
|
||||
{
|
||||
converted = new Pcm32BitToSampleProvider(provider);
|
||||
}
|
||||
} else if (provider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat) {
|
||||
if (provider.WaveFormat.BitsPerSample == 64) {
|
||||
}
|
||||
else if (provider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
|
||||
{
|
||||
if (provider.WaveFormat.BitsPerSample == 64)
|
||||
{
|
||||
converted = new WaveToSampleProvider64(provider);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
converted = new WaveToSampleProvider(provider);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Unsupported source encoding while adding to mixer.");
|
||||
}
|
||||
return ConvertToRightChannelCount(converted);
|
||||
@ -83,15 +99,18 @@ public class AudioPlaybackEngine : IDisposable
|
||||
mixer.AddMixerInput(input);
|
||||
}
|
||||
|
||||
public void RemoveMixerInput(ISampleProvider sound) {
|
||||
public void RemoveMixerInput(ISampleProvider sound)
|
||||
{
|
||||
mixer.RemoveMixerInput(sound);
|
||||
}
|
||||
|
||||
public void AddOnMixerInputEnded(EventHandler<SampleProviderEventArgs> e) {
|
||||
public void AddOnMixerInputEnded(EventHandler<SampleProviderEventArgs> e)
|
||||
{
|
||||
mixer.MixerInputEnded += e;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
public void Dispose()
|
||||
{
|
||||
outputDevice.Dispose();
|
||||
}
|
||||
}
|
@ -7,12 +7,14 @@ public class NetworkWavSound
|
||||
|
||||
public NetworkWavSound(string uri)
|
||||
{
|
||||
using (var mfr = new MediaFoundationReader(uri)) {
|
||||
using (var mfr = new MediaFoundationReader(uri))
|
||||
{
|
||||
WaveFormat = mfr.WaveFormat;
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int read = 0;
|
||||
using (var ms = new MemoryStream()) {
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
while ((read = mfr.Read(buffer, 0, buffer.Length)) > 0)
|
||||
ms.Write(buffer, 0, read);
|
||||
AudioData = ms.ToArray();
|
||||
|
@ -1,6 +1,7 @@
|
||||
using NAudio.Wave;
|
||||
|
||||
public class TTSPlayer {
|
||||
public class TTSPlayer
|
||||
{
|
||||
private PriorityQueue<TTSMessage, int> _messages; // ready to play
|
||||
private PriorityQueue<TTSMessage, int> _buffer;
|
||||
private Mutex _mutex;
|
||||
@ -8,77 +9,105 @@ public class TTSPlayer {
|
||||
|
||||
public ISampleProvider? Playing { get; set; }
|
||||
|
||||
public TTSPlayer() {
|
||||
public TTSPlayer()
|
||||
{
|
||||
_messages = new PriorityQueue<TTSMessage, int>();
|
||||
_buffer = new PriorityQueue<TTSMessage, int>();
|
||||
_mutex = new Mutex();
|
||||
_mutex2 = new Mutex();
|
||||
}
|
||||
|
||||
public void Add(TTSMessage message) {
|
||||
try {
|
||||
public void Add(TTSMessage message)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mutex2.WaitOne();
|
||||
_buffer.Enqueue(message, message.Priority);
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mutex2.ReleaseMutex();
|
||||
}
|
||||
}
|
||||
|
||||
public TTSMessage? ReceiveReady() {
|
||||
try {
|
||||
public TTSMessage? ReceiveReady()
|
||||
{
|
||||
try
|
||||
{
|
||||
_mutex.WaitOne();
|
||||
if (_messages.TryDequeue(out TTSMessage? message, out int _)) {
|
||||
if (_messages.TryDequeue(out TTSMessage? message, out int _))
|
||||
{
|
||||
return message;
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mutex.ReleaseMutex();
|
||||
}
|
||||
}
|
||||
|
||||
public TTSMessage? ReceiveBuffer() {
|
||||
try {
|
||||
public TTSMessage? ReceiveBuffer()
|
||||
{
|
||||
try
|
||||
{
|
||||
_mutex2.WaitOne();
|
||||
if (_buffer.TryDequeue(out TTSMessage? message, out int _)) {
|
||||
if (_buffer.TryDequeue(out TTSMessage? message, out int _))
|
||||
{
|
||||
return message;
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mutex2.ReleaseMutex();
|
||||
}
|
||||
}
|
||||
|
||||
public void Ready(TTSMessage message) {
|
||||
try {
|
||||
public void Ready(TTSMessage message)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mutex.WaitOne();
|
||||
_messages.Enqueue(message, message.Priority);
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mutex.ReleaseMutex();
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAll() {
|
||||
try {
|
||||
public void RemoveAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
_mutex2.WaitOne();
|
||||
_buffer.Clear();
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mutex2.ReleaseMutex();
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
_mutex.WaitOne();
|
||||
_messages.Clear();
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mutex.ReleaseMutex();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEmpty() {
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return _messages.Count == 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class TTSMessage {
|
||||
public class TTSMessage
|
||||
{
|
||||
public string? Voice { get; set; }
|
||||
public string? Channel { get; set; }
|
||||
public string? Username { get; set; }
|
||||
|
Reference in New Issue
Block a user