fixed music, and its now stereo.

This commit is contained in:
Kwoth 2015-12-31 20:40:09 +01:00
parent 24153df9d7
commit 4c3997b6fa
4 changed files with 44 additions and 13 deletions

View File

@ -11,7 +11,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Modules", "E:\O
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Commands", "E:\Ostalo\Discord.Net\src\Discord.Net.Commands.Net45\Discord.Net.Commands.csproj", "{1B5603B4-6F8F-4289-B945-7BAAE523D740}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Commands", "E:\Ostalo\Discord.Net\src\Discord.Net.Commands.Net45\Discord.Net.Commands.csproj", "{1B5603B4-6F8F-4289-B945-7BAAE523D740}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Audio", "E:\Ostalo\Discord.Net\src\Discord.Net.Audio.Net5\Discord.Net.Audio.csproj", "{7BFEF748-B934-4621-9B11-6302E3A9F6B3}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Audio", "E:\Ostalo\Discord.Net\src\Discord.Net.Audio.Net45\Discord.Net.Audio.csproj", "{7BFEF748-B934-4621-9B11-6302E3A9F6B3}"
EndProject EndProject
Global Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution GlobalSection(SharedMSBuildProjectFiles) = preSolution

View File

@ -21,7 +21,7 @@ namespace NadekoBot.Modules
private static bool exit = true; private static bool exit = true;
public static bool NextSong = false; public static bool NextSong = false;
public static DiscordAudioClient Voice; public static IAudioClient Voice;
public static Channel VoiceChannel; public static Channel VoiceChannel;
public static bool Pause = false; public static bool Pause = false;
public static List<YouTubeVideo> SongQueue = new List<YouTubeVideo>(); public static List<YouTubeVideo> SongQueue = new List<YouTubeVideo>();
@ -96,6 +96,21 @@ namespace NadekoBot.Modules
} }
}); });
cgb.CreateCommand("testq")
.Description("Queue a song using a multi/single word name.\nUsage: `!m q Dream Of Venice`")
.Parameter("Query", ParameterType.Unparsed)
.Do(async e => {
var youtube = YouTube.Default;
var video = youtube.GetAllVideos(e.GetArg("Query"))
.Where(v => v.AdaptiveKind == AdaptiveKind.Audio)
.OrderByDescending(v => v.AudioBitrate).FirstOrDefault();
if (video?.Uri != "" && video.Uri != null) {
SongQueue.Add(video);
await e.Send("**Queued** " + video.FullName);
}
});
cgb.CreateCommand("q") cgb.CreateCommand("q")
.Alias("yq") .Alias("yq")
.Description("Queue a song using a multi/single word name.\nUsage: `!m q Dream Of Venice`") .Description("Queue a song using a multi/single word name.\nUsage: `!m q Dream Of Venice`")
@ -145,7 +160,7 @@ namespace NadekoBot.Modules
{ {
if (Voice != null) return; if (Voice != null) return;
VoiceChannel = e.Server.FindChannels(e.GetArg("ChannelName").Trim(), ChannelType.Voice).FirstOrDefault(); VoiceChannel = e.Server.FindChannels(e.GetArg("ChannelName").Trim(), ChannelType.Voice).FirstOrDefault();
//Voice = await client.JoinVoiceServer(VoiceChannel); Voice = await client.Audio().Join(VoiceChannel);
Exit = false; Exit = false;
NextSong = false; NextSong = false;
Pause = false; Pause = false;
@ -166,18 +181,28 @@ namespace NadekoBot.Modules
await e.Send( "Exiting..."); await e.Send( "Exiting...");
return; return;
} }
int blockSize = 1920; int blockSize = 3840;
byte[] buffer = new byte[1920]; byte[] buffer = new byte[3840];
//float multiplier = 1.0f / 48000 / 2;
var msg = await e.Send( "Playing " + Music.CurrentSong.FullName + " [00:00]"); var msg = await e.Send( "Playing " + Music.CurrentSong.FullName + " [00:00]");
int counter = 0; int counter = 0;
int byteCount; int byteCount;
using (var stream = GetAudioFileStream(Music.CurrentSong.Uri)) using (var stream = GetAudioFileStream(Music.CurrentSong.Uri))
{ {
while ((byteCount = stream.Read(buffer, 0, blockSize)) > 0) var m = await e.Send("Downloading song...");
var memStream = new MemoryStream();
while (true) {
byte[] buff = new byte[0x4000 * 10];
int read = stream.Read(buff, 0, buff.Length);
if (read <= 0) break;
memStream.Write(buff, 0, read);
}
e.Send("Song downloaded");
memStream.Position = 0;
while ((byteCount = memStream.Read(buffer, 0, blockSize)) > 0)
{ {
// Voice.SendVoicePCM(buffer, byteCount); Voice.Send(buffer, byteCount);
counter += blockSize; counter += blockSize;
if (NextSong) if (NextSong)
{ {
@ -194,10 +219,10 @@ namespace NadekoBot.Modules
} }
}); });
} }
// await Voice.WaitVoice(); Voice.Wait();
} }
catch (Exception ex) { Console.WriteLine(ex.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); }
// await client.LeaveVoiceServer(VoiceChannel.Server); await Voice.Disconnect();
Voice = null; Voice = null;
VoiceChannel = null; VoiceChannel = null;
}); });
@ -209,7 +234,7 @@ namespace NadekoBot.Modules
Process p = Process.Start(new ProcessStartInfo() Process p = Process.Start(new ProcessStartInfo()
{ {
FileName = "ffmpeg", FileName = "ffmpeg",
Arguments = "-i \"" + Uri.EscapeUriString(file) + "\" -f s16le -ar 48000 -af volume=1 -ac 1 pipe:1 ", Arguments = "-i \"" + Uri.EscapeUriString(file) + "\" -f s16le -ar 48000 -af volume=1 -ac 2 pipe:1 ",
UseShellExecute = false, UseShellExecute = false,
RedirectStandardOutput = true RedirectStandardOutput = true
}); });

View File

@ -7,6 +7,7 @@ using Discord.Commands;
using NadekoBot.Modules; using NadekoBot.Modules;
using Discord.Modules; using Discord.Modules;
using Discord.Legacy; using Discord.Legacy;
using Discord.Audio;
namespace NadekoBot namespace NadekoBot
{ {
@ -63,12 +64,17 @@ namespace NadekoBot
//create module service //create module service
var modules = client.Services.Add<ModuleService>(new ModuleService()); var modules = client.Services.Add<ModuleService>(new ModuleService());
//add audio service
var audio = client.Services.Add<AudioService>(new AudioService(new AudioServiceConfig() {
Channels = 2
}));
//install modules //install modules
modules.Install(new Administration(), "Administration", FilterType.Unrestricted); modules.Install(new Administration(), "Administration", FilterType.Unrestricted);
modules.Install(new Conversations(), "Conversations", FilterType.Unrestricted); modules.Install(new Conversations(), "Conversations", FilterType.Unrestricted);
modules.Install(new Gambling(), "Gambling", FilterType.Unrestricted); modules.Install(new Gambling(), "Gambling", FilterType.Unrestricted);
modules.Install(new Games(), "Games", FilterType.Unrestricted); modules.Install(new Games(), "Games", FilterType.Unrestricted);
//modules.Install(new Music(), "Music", FilterType.Unrestricted); modules.Install(new Music(), "Music", FilterType.Unrestricted);
modules.Install(new Searches(), "Searches", FilterType.Unrestricted); modules.Install(new Searches(), "Searches", FilterType.Unrestricted);
//run the bot //run the bot

View File

@ -127,7 +127,7 @@
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="E:\Ostalo\Discord.Net\src\Discord.Net.Audio.Net5\Discord.Net.Audio.csproj"> <ProjectReference Include="E:\Ostalo\Discord.Net\src\Discord.Net.Audio.Net45\Discord.Net.Audio.csproj">
<Project>{7bfef748-b934-4621-9b11-6302e3a9f6b3}</Project> <Project>{7bfef748-b934-4621-9b11-6302e3a9f6b3}</Project>
<Name>Discord.Net.Audio</Name> <Name>Discord.Net.Audio</Name>
</ProjectReference> </ProjectReference>