<commit_before># Author:  <NAME>
# Created: 2018-04-21
# Copyright (C) 2018, <NAME>
# License: MIT

import wave
import array

def save(params, filename, source):
    '''
    Write a sequence of samples as a WAV file
    Currently a 16 bit mono file
    '''
    writer = wave.open(filename, 'wb');
    # Set the WAV file parameters, currently default values
    writer.setnchannels(1)
    writer.setsampwidth(2)
    writer.setframerate(params.get_sample_rate())
    data_out = array.array('h')
    for x in source:
        data_out.append(int(x * 32766))
    writer.writeframes(data_out.tostring())
    writer.close()<commit_msg>Add WAV reader<commit_after># Author:  <NAME>
# Created: 2018-04-21
# Copyright (C) 2018, <NAME>
# License: MIT

from scipy.io.wavfile import read, write
from pysound.buffer import BufferParams

def save(params, filename, source):
    '''
    Write a sequence of samples as a WAV file
    '''
    write(filename, params.get_sample_rate(), source)

def load_with_params(filename, channel=0):
    '''
    Read a sequence of samples from a WAV file
    Return the buffer params and data
    '''
    rate, data = read(filename)
    params = BufferParams(data.shape[0], rate)

    # If the data is mono, return it
    if data.ndim == 1:
        return params, data

    # Otherwise return requested channel
    return params, data[channel]

def load(filename, channel=0):
    '''
    Read a sequence of samples from a WAV file
    Return the data
    '''
    _, data = load_with_params(filename, channel)
    return data

{'fraction_non_alphanumeric': 0.10621761658031088, 'fraction_numerical': 0.023963730569948185, 'mean_word_length': 3.256198347107438, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1316307', 'n_tokens_mistral': 511, 'n_tokens_neox': 479, 'n_words': 159}