相关文章推荐
长情的充电器  ·  Spring在bean ...·  1 年前    · 
机灵的铁链  ·  unity怎么获取 android ...·  1 年前    · 
要出家的烈马  ·  三. ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Want to improve this question? Update the question so it focuses on one problem only by editing this post .

Closed 6 months ago .

You would need some kind of signal processing library that you can use to identify the peak amplitude Tyler Liu Dec 25, 2022 at 19:53 As mention by @TylerLiu you could use wave and struct to get the peak of an audio file. Open the wav file with wave, and unpack the audio data using struct.unpack. Find the peak with max, and convert the peak value to dB Dexty Dec 25, 2022 at 20:00

here is an example of using wave, struct and math in Python to get the peak of an audio file.

import wave
import struct
import math
# Open the audio file
with wave.open('audio.wav', 'r') as audio:
    # Extract the raw audio data
    raw_data = audio.readframes(audio.getnframes())
# Convert the raw audio data to a list of integers
samples = struct.unpack('{n}h'.format(n=audio.getnframes()), raw_data)
# Find the peak sample
peak = max(samples)
# Calculate the reference value based on the bit depth of the audio file
reference_value = 2**(audio.getsampwidth() * 8 - 1)
# Calculate the peak value in dBFS, using the maximum possible sample value as the reference value
peak_dB = 20 * math.log10(peak / reference_value)
print(peak_dB)