import contextlib
import wave
import audioop


def read_wave(path):
	"""Reads a .wav file.
	Takes the path, and returns (PCM audio data, sample rate).
	"""
	with contextlib.closing(wave.open(path, 'rb')) as wf:
		num_channels = wf.getnchannels()
		assert num_channels == 1
		sample_width = wf.getsampwidth()
		assert sample_width == 2
		sample_rate = wf.getframerate()

		n_frames = wf.getnframes()
		data = wf.readframes(n_frames)

		converted = audioop.ratecv(data, sample_width, num_channels, sample_rate, 32000, None)
		return converted[0], 32000