replace emoji string

This commit is contained in:
sim1222 2023-07-26 22:36:00 +09:00
parent 219cf0da88
commit 7995cdc5c5

View File

@ -7,6 +7,7 @@ using Discord.WebSocket;
using ManagedBass;
using Microsoft.Extensions.DependencyInjection;
using NAudio.Wave;
using NLog;
namespace Elementary.Audio;
@ -25,6 +26,8 @@ public class AudioManager
private PlaybackQueue _playbackQueue;
// private AudioMixer _audioMixer;
private ILogger _logger;
public bool isConnected;
public AudioManager(IServiceProvider services, DiscordSocketClient client, SozaiAPI sozaiApi,
@ -35,11 +38,22 @@ public class AudioManager
_sozaiAPI = sozaiApi;
_voicevoxAPI = voicevoxApi;
_audioConverter = new();
_logger = LogManager.GetCurrentClassLogger();
}
public async Task JoinChannel(IVoiceChannel channel)
{
_audioClient = await channel.ConnectAsync(true);
// _audioClient.ClientDisconnected += async (exception) =>
// {
// isConnected = false;
// await JoinChannel(channel);
// };
_audioClient.Disconnected += async (exception) =>
{
isConnected = false;
await JoinChannel(channel);
};
_audioStream = _audioClient.CreatePCMStream(AudioApplication.Music, 128 * 1024);
@ -53,14 +67,20 @@ public class AudioManager
public async Task LeaveChannel()
{
await _audioClient.StopAsync();
await _audioStream.FlushAsync();
_audioStream.Dispose();
_audioClient.Dispose();
}
public async Task PlayAudio(string path)
{
await using var wave = _audioConverter.CreateStreamFromFilePath(path, 0.15f);
_logger.Log(LogLevel.Info, $"Playing {path} {wave.Length} bytes");
// _audioMixer.AddStream(wave);
await wave.CopyToAsync(_audioStream);
// GC.Collect();
}
public async Task PlayText(string text)
@ -68,6 +88,7 @@ public class AudioManager
if (text.Contains("```")) text = "コードブロック";
if (text.StartsWith("!") || text.StartsWith(".")) return;
text = Regex.Replace(text, @"https?://[\w/:%#\$&\?\(\)~\.=\+\-]+", "URL");
text = Regex.Replace(text, @"<:[\w]+:[\d]+>", m => m.Value.Split(":")[1]);
float volume = 0.12f;
@ -82,6 +103,7 @@ public class AudioManager
await using var wave = _audioConverter.CreateStreamFromStream(stream, volume);
// _audioMixer.AddStream(wave);
await wave.CopyToAsync(_audioStream);
// GC.Collect();
}
public async Task StopAudio()