Discord.NET 1.0.2将语音发送到语音通道不起作用

时间:2018-10-17 11:44:07

标签: ffmpeg voice discord.net opus libsodium

我在语音方面做了类似Discord.Net文档指南的所有工作- https://discord.foxbot.me/latest/guides/voice/sending-voice.html 而且它不起作用,该机器人只是加入了语音通道,但没有发出任何声音。 我在bot目录中的PATH和ffmpeg.exe中都安装了ffmpeg以及opus.dll和libsodium.dll,所以我不知道这是什么问题...

    public class gil : ModuleBase<SocketCommandContext>
{
    [Command("join")]
    public async Task JoinChannel(IVoiceChannel channel = null)
    {
        // Get the audio channel
        channel = channel ?? (Context.Message.Author as IGuildUser)?.VoiceChannel;
        if (channel == null) { await Context.Message.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return; }

        // For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
        var audioClient = await channel.ConnectAsync();

        await SendAsync(audioClient,"audio/hello.mp3");
    }

    private Process CreateStream(string path)
    {
        return Process.Start(new ProcessStartInfo
        {
            FileName = "ffmpeg.exe",
            Arguments = $"-hide_banner -loglevel panic -i \"{path}\" -ac 2 -f s16le -ar 48000 pipe:1",
            UseShellExecute = false,
            RedirectStandardOutput = true,
        });
    }

    private async Task SendAsync(IAudioClient client, string path)
    {
        // Create FFmpeg using the previous example
        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(); }
        }
    }
}

请帮助

0 个答案:

没有答案