Commit 27ad221c authored by Anthony Larcher's avatar Anthony Larcher
Browse files

wav flag

parent 9a82a87b
......@@ -189,5 +189,5 @@ __maintainer__ = "Anthony Larcher"
__email__ = "anthony.larcher@univ-lemans.fr"
__status__ = "Production"
__docformat__ = 'reStructuredText'
__version__="1.3.6.8"
__version__="1.3.6.9"
......@@ -34,6 +34,7 @@ import logging
import math
import numpy
import os
import soundfile
import struct
import warnings
import wave
......@@ -53,6 +54,8 @@ __status__ = "Production"
__docformat__ = 'reStructuredText'
wav_flag = "float32" # Could be "int16"
# HTK parameters
WAVEFORM = 0
LPC = 1
......@@ -127,13 +130,18 @@ def read_wav(input_file_name):
:param input_file_name:
:return:
"""
with wave.open(input_file_name, "r") as wfh:
(nchannels, sampwidth, framerate, nframes, comptype, compname) = wfh.getparams()
raw = wfh.readframes(nframes * nchannels)
out = struct.unpack_from("%dh" % nframes * nchannels, raw)
sig = numpy.reshape(numpy.array(out), (-1, nchannels)).squeeze()
return sig.astype(numpy.float32), framerate, sampwidth
#with wave.open(input_file_name, "r") as wfh:
# (nchannels, sampwidth, framerate, nframes, comptype, compname) = wfh.getparams()
# raw = wfh.readframes(nframes * nchannels)
# out = struct.unpack_from("%dh" % nframes * nchannels, raw)
# sig = numpy.reshape(numpy.array(out), (-1, nchannels)).squeeze()
# return sig.astype(numpy.float32), framerate, sampwidth
nfo = soundfile.info(input_file_name)
sig, sample_rate = soundfile.read(input_file_name, dtype=wav_flag)
sig = numpy.reshape(numpy.array(sig), (-1, nfo.channels)).squeeze()
sig = sig.astype(numpy.float32)
return sig, sample_rate, 4
def pcmu2lin(p, s=4004.189931):
"""Convert Mu-law PCM to linear X=(P,S)
......
......@@ -1088,4 +1088,3 @@ def extract_sliding_embedding(idmap_name,
transform_pipeline=transform_pipeline)
return embeddings
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment