<jupyter_start><jupyter_text>Single file<jupyter_code># Read file to get buffer
ifile = wave.open("ti46_0am1s1t0.wav")

sample_rate = ifile.getframerate()

samples = ifile.getnframes()
audio = ifile.readframes(samples)

# Convert buffer to float32 using NumPy                                                                                 
audio_as_np_int16 = np.frombuffer(audio, dtype=np.int16)
audio_as_np_float64 = audio_as_np_int16.astype(np.float64)

# Normalise float64 array so that values are between -1.0 and +1.0                                                      
max_int16 = 2**15
audio_normalised = audio_as_np_float64 / max_int16
ifile.close()
audio_normalised.shape
calc = LyonCalc()
decimation_factor = 64
coch = calc.lyon_passive_ear(audio_normalised, sample_rate, decimation_factor)
print(coch.shape)
np.savetxt('array.csv', coch, delimiter=',')<jupyter_output><empty_output><jupyter_text>Multiple Files<jupyter_code>!unzip train.zip
def read_file(name):
  # Read file to get buffer
  ifile = wave.open(name)

  sample_rate = ifile.getframerate()

  samples = ifile.getnframes()
  audio = ifile.readframes(samples)

  # Convert buffer to float32 using NumPy                                                                                 
  audio_as_np_int16 = np.frombuffer(audio, dtype=np.int16)
  audio_as_np_float64 = audio_as_np_int16.astype(np.float64)

  # Normalise float64 array so that values are between -1.0 and +1.0                                                      
  max_int16 = 2**15
  audio_normalised = audio_as_np_float64 / max_int16
  ifile.close()
  return (audio_normalised, sample_rate)
for i in ["f", "m"]:
  for j in [1, 2, 3]:
    foldername = "traincsv/" + i + str(j) + "/"
    os.makedirs(os.path.dirname(foldername), exist_ok=True)
    for k in range(10):
      for l in range(10):
        filepath = "train/" + i + str(j) + "/0" + str(k) + i + str(j) + "set" + str(l) + ".wav"
        csvpath = "traincsv/" + i + str(j) + "/0" + str(k) + i + str(j) + "set" + str(l) + ".csv"
        audio_normalised, sample_rate = read_file(filepath)
        calc = LyonCalc()
        decimation_factor = 64
        coch = calc.lyon_passive_ear(audio_normalised, sample_rate, decimation_factor)
        np.savetxt(csvpath, coch, delimiter=',')
        print(csvpath)

!zip -r traincsv.zip traincsv<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1128486897717667, 'fraction_numerical': 0.03085376162299239, 'mean_word_length': 2.5755287009063443, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '330166', 'license': 'MIT', 'n_tokens_mistral': 851, 'n_tokens_neox': 810, 'n_words': 170, 'path': 'PreProcessing/SpeechPreprocessing.ipynb', 'repo_name': 'AnDa-creator/EE746-NeuromorphicEngineering', 'size': '2366'}