<jupyter_start><jupyter_text>Tube FinderThis notebook logs our efforts towards making a 2-tube model that best approximates Jacob's voice.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

from scipy.io import wavfile<jupyter_output><empty_output><jupyter_text>Target Waveform: Sanity CheckFirst, let's load our test subject's recording and verify the spectrogram looks normal. This is our "target" waveform -- our model is aiming to produce a similar sound.<jupyter_code>sampling_rate, target_waveform = wavfile.read('target_sounds/jacob-aah-1.wav')

# This is a stereo wav. Take only the first audio track. 
target_waveform = target_waveform[:,0]
# Visualize the vocal spectrogram. 
_, _, _, _ = plt.specgram(target_waveform, Fs=sampling_rate, NFFT=8192)
plt.ylim([0,2000])
plt.xlabel('Time(s)')
plt.ylabel('Frequency (Hz)')<jupyter_output><empty_output><jupyter_text>Looking good! Let's narrow our data down a bit, just to avoid any "quiet spots" near the beginning or end of the track.<jupyter_code>target_waveform = target_waveform[round(0.05 * len(target_waveform)) : round(0.95 * len(target_waveform))]
print(target_waveform.shape)<jupyter_output>(43632,)<jupyter_text>Optimizing The Generated WaveformWe've already implemented the optimizer in `n_tube_optimizer.py`. Let's look through what it can give us.<jupyter_code>import n_tube_optimizer as nto
import metrics<jupyter_output>/usr/lib/python3.9/site-packages/tslearn/bases/bases.py:15: UserWarning: h5py not installed, hdf5 features will not be supported.
Install h5py to use hdf5 features: http://docs.h5py.org/
  warn(h5py_msg)<jupyter_text>We got a warning -- our installation of `tslearn` doesn't support en-masse data storage, because `h5py` isn't installed. This doesn't affect what we're doing now, so we can ignore it.<jupyter_code># This interface isn't very intuitive, I know. Might clean it up later. 
bounds = [
    (5, 15), # First tube can be 5-25 cm long
    (1, 3), # First tube can be 1-5 cm^2 across
    (5, 15), # First tube can be 5-25 cm long
    (1, 3), # First tube can be 1-5 cm^2 across
]
tubes_optimal = nto.find_optimal_parameters(target_waveform, metrics.mse_loss, bounds, 10_000)
print(tubes_optimal)<jupyter_output>((10.0, 2.264491853301425), (10.0, 1.700099280816976))
{'fraction_non_alphanumeric': 0.10276679841897234, 'fraction_numerical': 0.043478260869565216, 'mean_word_length': 5.680351906158358, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '477056', 'license': 'MIT', 'n_tokens_mistral': 860, 'n_tokens_neox': 774, 'n_words': 235, 'path': 'find-best-tube-model.ipynb', 'repo_name': 'yashlala/vocal-tube-model', 'size': '2277'}