MCPcopy Create free account
hub / github.com/Mercury7353/PyBench / read_wave_file

Function read_wave_file

data/unit_test/tests.py:1396–1411  ·  view source on GitHub ↗
(file_path)

Source from the content-addressed store, hash-verified

1394import numpy as np
1395
1396def read_wave_file(file_path):
1397 with wave.open(file_path, 'rb') as wf:
1398 # 获取音频文件的参数
1399 n_channels = wf.getnchannels()
1400 sample_width = wf.getsampwidth()
1401 frame_rate = wf.getframerate()
1402 n_frames = wf.getnframes()
1403
1404 # 读取音频数据
1405 audio_data = wf.readframes(n_frames)
1406
1407 # 将音频数据转换为 numpy 数组
1408 audio_array = np.frombuffer(audio_data, dtype=np.int16)
1409 audio_array = audio_array / (2**(8*sample_width-1)) # 归一化到 -1 到 1 之间
1410
1411 return audio_array, frame_rate
1412
1413def calculate_dbfs(audio_array):
1414 # 计算音频信号的均方根(RMS)值

Callers 1

test_task_146Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected