0

似乎没有任何函数可以获取这些值

import vlc

p = vlc.MediaPlayer(path/to/file.mp3)
p.play()

在这里我需要得到声音的频率、音高和其他属性。我不确定这是否可以使用 vlc-python,任何其他解决方案也会有所帮助

4

2 回答 2

0

我认为您可能需要一个额外的库来实现您想要的。这是一个关于如何使用 Python 构建音频频谱分析仪的视频教程: https ://youtu.be/AShHJdSIxkY

这是来自该视频评论者的最终 --python2 -- 代码(感谢用户 Hey Jose!)

#! /usr/bin/python

import pyaudio
import struct
import numpy as np
import matplotlib.pyplot as plt
import time

#%matplotlib tk

CHUNK = 4000
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 16000

p = pyaudio.PyAudio()

chosen_device_index = -1
for x in xrange(0,p.get_device_count()):
    info = p.get_device_info_by_index(x)
    #print p.get_device_info_by_index(x)
    if info["name"] == "pulse":
        chosen_device_index = info["index"]
        print "Chosen index: ", chosen_device_index


stream = p.open(format=FORMAT,
 channels=CHANNELS,
 rate=RATE,
 input_device_index=chosen_device_index,
 input=True,
 output=True,
 frames_per_buffer=CHUNK
 )
 
plt.ion()
fig, ax = plt.subplots()

x = np.arange(0, CHUNK)
data = stream.read(CHUNK)
data_int16 = struct.unpack(str(CHUNK) + 'h', data)
line, = ax.plot(x, data_int16)
#ax.set_xlim([xmin,xmax])
ax.set_ylim([-2**15,(2**15)-1])

while True:
 data = struct.unpack(str(CHUNK) + 'h', stream.read(CHUNK))
 line.set_ydata(data)
 fig.canvas.draw()
 fig.canvas.flush_events()

本教程使用 PyAudio ( https://people.csail.mit.edu/hubert/pyaudio/docs/ )

我还没有完成教程,但是阅读示例代码,他们似乎采取了以块读取音频流并将字节映射到绘图的 y 轴的方法。

如果这不适合您的应用程序,您可以查看

从音频文件中提取音高特征

这个问题的答案表明这个图书馆:http ://digitalmusics.dartmouth.edu/~mcasey/bregman/

于 2020-11-17T18:14:06.367 回答
0

使用AudioEqualizer频率信息https://www.olivieraubert.net/vlc/python-ctypes/doc/vlc.AudioEqualizer-class.html

音轨将包含频道和费率信息https://www.videolan.org/developers/vlc-branch/doc/doxygen/html/structlibvlc__audio__track__t.html

结构也libvlc_media_stats_t有更多信息https://www.videolan.org/developers/vlc-branch/doc/doxygen/html/structlibvlc__media__stats__t.html喜欢

int     i_read_bytes
float   f_input_bitrate
int     i_demux_read_bytes
float   f_demux_bitrate
int     i_demux_corrupted
int     i_demux_discontinuity
int     i_decoded_video
int     i_decoded_audio
int     i_displayed_pictures
int     i_lost_pictures
int     i_played_abuffers
int     i_lost_abuffers
int     i_sent_packets
int     i_sent_bytes
float   f_send_bitrate
于 2020-11-23T07:07:33.093 回答