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