如何在python的时间戳中获取音频“响度”?

时间:2019-05-04 06:45:27

标签: python audio

我正在尝试使用python可视化音频,但似乎无法获得歌曲的“响度”

现在我的代码:

import wave
import simpleaudio as sa
import time
import sys

FILENAME = "mySong.wav"


wave_obj = sa.WaveObject.from_wave_file(FILENAME)
play_obj = wave_obj.play()

song = wave.open(FILENAME, 'rb')
songFrames = song.readframes(song.getnframes())
songFrameRate = song.getparams()[2]
totalTime = song.getnframes()/songFrameRate
print('total Time = ' + str(totalTime))
startTime = time.time()

print('--')
run=True
while run:
    elapsedTime = time.time()-startTime
    i = round((elapsedTime/totalTime)*len(songFrames))
    curFrame = songFrames[i]

    sys.stdout.write("\r")
    for i in range(round(curFrame/4)):
        sys.stdout.write('■')
    for j in range(100-round(curFrame/4)):
        sys.stdout.write(' ')
    sys.stdout.flush()

当没有声音时,没有酒吧,这是预期的。但是,当有声音时,“ bar”是杂音,根本与音频不匹配,有人知道为什么吗?

以下是我需要帮助的地方:

import usefulLibrary

fileName = 'my_file.wav'
wav_file = usefulLibrary.read(fileName)

for sample in wav_file:
    print("the audio is at level: " + str(sample))

0 个答案:

没有答案