* Tweaks to audio docs * Make it more obvious that -1 means infinitytags/2.0.0-beta
@@ -1,5 +1,6 @@ | |||||
using System; | using System; | ||||
using System.Reflection; | using System.Reflection; | ||||
using System.Threading; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Microsoft.Extensions.DependencyInjection; | using Microsoft.Extensions.DependencyInjection; | ||||
using Discord; | using Discord; | ||||
@@ -88,7 +89,7 @@ class Program | |||||
await _client.StartAsync(); | await _client.StartAsync(); | ||||
// Wait infinitely so your bot actually stays connected. | // Wait infinitely so your bot actually stays connected. | ||||
await Task.Delay(-1); | |||||
await Task.Delay(Timeout.Infinite); | |||||
} | } | ||||
private IServiceProvider _services; | private IServiceProvider _services; | ||||
@@ -1,11 +1,10 @@ | |||||
private Process CreateStream(string path) | private Process CreateStream(string path) | ||||
{ | { | ||||
var ffmpeg = new ProcessStartInfo | |||||
return Process.Start(new ProcessStartInfo | |||||
{ | { | ||||
FileName = "ffmpeg", | FileName = "ffmpeg", | ||||
Arguments = $"-i {path} -ac 2 -f s16le -ar 48000 pipe:1", | |||||
Arguments = $"-hide_banner -loglevel panic -i \"{path}\" -ac 2 -f s16le -ar 48000 pipe:1", | |||||
UseShellExecute = false, | UseShellExecute = false, | ||||
RedirectStandardOutput = true, | RedirectStandardOutput = true, | ||||
}; | |||||
return Process.Start(ffmpeg); | |||||
} | |||||
}); | |||||
} |
@@ -1,9 +1,11 @@ | |||||
private async Task SendAsync(IAudioClient client, string path) | private async Task SendAsync(IAudioClient client, string path) | ||||
{ | { | ||||
// Create FFmpeg using the previous example | // Create FFmpeg using the previous example | ||||
var ffmpeg = CreateStream(path); | |||||
var output = ffmpeg.StandardOutput.BaseStream; | |||||
var discord = client.CreatePCMStream(AudioApplication.Mixed); | |||||
await output.CopyToAsync(discord); | |||||
await discord.FlushAsync(); | |||||
using (var ffmpeg = CreateStream(path)) | |||||
using (var output = ffmpeg.StandardOutput.BaseStream) | |||||
using (var discord = client.CreatePCMStream(AudioApplication.Mixed)) | |||||
{ | |||||
try { await output.CopyToAsync(discord); } | |||||
finally { await discord.FlushAsync(); } | |||||
} | |||||
} | } |
@@ -7,4 +7,4 @@ public async Task JoinChannel(IVoiceChannel channel = null) | |||||
// For the next step with transmitting audio, you would want to pass this Audio Client in to a service. | // For the next step with transmitting audio, you would want to pass this Audio Client in to a service. | ||||
var audioClient = await channel.ConnectAsync(); | var audioClient = await channel.ConnectAsync(); | ||||
} | |||||
} |