首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >流音频使用yt-dlp kn python而不是下载文件。

流音频使用yt-dlp kn python而不是下载文件。
EN

Stack Overflow用户
提问于 2022-02-19 18:33:01
回答 1查看 699关注 0票数 1

我想为一个不和谐的机器人流音频,而不是下载文件并从中提取音频文件。我尝试过来自Is there a way to directly stream audio from a youtube video using youtube-dl or pafy library in python 3.7?的代码

EN

回答 1

Stack Overflow用户

发布于 2022-08-02 15:24:15

是的很简单

  1. yt_dlp
  2. Import

使用本守则:

代码语言:javascript
运行
复制
ffmpeg_options = {'options': '-vn'}
ydl_opts = {'format': 'bestaudio'}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    song_info = ydl.extract_info(url, download=False)

ctx.voice_client.play(discord.FFmpegPCMAudio(song_info["url"], **ffmpeg_options))    

示例:

代码语言:javascript
运行
复制
async def streamx(ctx, url):
voiceChannel = ctx.message.author.voice.channel //get Message Sender Channel. When you want it to join without a seperat function.
await voiceChannel.connect() //same applies to this
ffmpeg_options = {'options': '-vn'}
ydl_opts = {'format': 'bestaudio'}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    song_info = ydl.extract_info(url, download=False)

ctx.voice_client.play(discord.FFmpegPCMAudio(song_info["url"], **ffmpeg_options))    

您可以使用来自ydl_opts的文档来调整yt_dlp。

欢迎光临!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71187954

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档