Welcome to mirror list, hosted at ThFree Co, Russian Federation.

wav.py « utils « lpcnet « torch « dnn - gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3ed811f5fe9892df956b849a8ee300f6ff7ab4ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import wave

def wavwrite16(filename, x, fs):
    """ writes x as int16 to file with name filename

        If x.dtype is int16 x is written as is. Otherwise,
        it is scaled by 2**15 - 1 and converted to int16.
    """
    if x.dtype != 'int16':
        x = ((2**15 - 1) * x).astype('int16')

    with wave.open(filename, 'wb') as f:
        f.setparams((1, 2, fs, len(x), 'NONE', ""))
        f.writeframes(x.tobytes())