如何从python-VLC获取音频样本 [英] How to get audio samples from python-VLC

查看:46
本文介绍了如何从python-VLC获取音频样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要什么

我正在开发带有样本分析器的音乐播放器.我的问题是我目前正在使用 pydub 从歌曲中获取样本,但是随着歌曲变长,两者变得越不同步.我已经让两者完全同步,pydub 恰好读出了它 [我什至同时启动它们,实际上两者实际上逐渐与音频不同步,并且随着歌曲继续播放而更多].

基本上,是否有与 pydub.AudioSegment.get_array_of_samples() 等效的 python-vlc?

您可以在此处查看 python-vlc 文档:https://www.olivieraubert.net/vlc/python-ctypes/doc/

我的尝试

  1. python-vlc 有 sound.get_time() 返回最后更新的时间(以毫秒为单位).这个命令的问题不在于它每半秒左右更新一次[我找到了解决方法],而是它没有返回准确的时间.我可以使用 time.monotonic() 从它开始播放时开始计时.随着时间的推移,get_time() 与计时器有很大不同.我得到了 195 毫秒、294 毫秒和 217 毫秒的差异.

  2. 我尝试通过 threading 模块使用外部计时器.看来 pydub.AudioSegment[index] 根本不同步.

  3. 从 py-vlc 中的 sound.get_time() 缩放到 pydub 中的 len(sound).这不会按预期工作.我不能告诉你为什么,但它仍然不同步.

  4. 使用 sound.get_time() 和随时间增加的平均偏移.看起来 pydub.AudioSegment[index] 没有正确对齐.

  5. 使用 aubio.它只读取 WAV 文件,对于实时分析器,首先转换为 WAV 需要很长时间.

我发现的事情

  • 我查看了每首歌曲的毫秒数,pydub 的 len(sound) 和 python-vlc 的 sound.get_length() 通常不同10 秒左右.

行不通的事情

  • 使用 pydub 的 play() 命令.我不喜欢它,因为它的局限性很大.
  • 使用 py-vlc 以外的其他东西来播放音频,VLC 具有许多无法复制的功能.

以前的建议

我很好奇

  • 是否有适用于 Audacity 的 Python 模块?我一直在找,没找到.如果可能的话,我还可以使用其他一些可以与 Audacity 交互的命令行工具[我知道内置的命令行实用程序根本没有做太多]

解决方案

你可能想直接使用 ffmpeg 来解决这个问题.

What I need

I am working on a music player with a sample analyzer. My issue is that I am currently using pydub to get the samples from the song, but as the song gets longer, the more out of sync the two become. I have made the two literally in sync, pydub just so happens to read out of it [I even started them at the same time, the two actually progressively de-synced with audio alone and more so as the song continues playing].

Basically, is there a python-vlc equivalent to pydub.AudioSegment.get_array_of_samples()?

You can look at the python-vlc docs here: https://www.olivieraubert.net/vlc/python-ctypes/doc/

What I've tried

  1. python-vlc has sound.get_time() which returns the last updated time in milliseconds. The issue with this command is not that it only updates every half a second or so [I've found a way around that] but that it doesn't return the accurate time. I can start a timer from when it starts playing using time.monotonic(). As time progresses, the get_time() wildly varies from the timer. I've gotten a difference of 195ms, 294ms and 217ms.

  2. I tried using an external timer using the threading module. It appears that pydub.AudioSegment[index] is not in sync whatsoever.

  3. Scaling from sound.get_time() in py-vlc to len(sound) in pydub. This doesn't work as expected. I cannot tell you why but it is still desynced.

  4. Using sound.get_time() with an average offset that increases over time. It appears that pydub.AudioSegment[index] doesn't line up properly.

  5. Using aubio. It only reads WAV files, and for a live analyzer, converting to a WAV first would take too long.

Things I found out

  • I've looked at how long each song is in milliseconds, len(sound) for pydub and sound.get_length() for python-vlc is different usually by 10 or so seconds.

Things that won't work

  • Using pydub's play() command. I don't like it because it's very limiting.
  • Using something else than py-vlc to play the audio, VLC has many features that just cannot be replicated.

Previous suggestions

I'm curious

  • Is there a python module for Audacity? I've been looking and couldn't find it. I can also use some other command line tool that can interact with Audacity if possible [I know the built in command line utility doesn't do much at all]

解决方案

You probably want to use ffmpeg directly for this.

这篇关于如何从python-VLC获取音频样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆