<jupyter_start><jupyter_text>This notebook uses sphinx via pocketsphinx to convert continuous recording of speech to a set of phonemes. On Mac you can install pocketsphinx with `brew install cmu-pocketsphinx`. This only works on audio that is 16KHz, and works at something like 5% realtime rate. So a 10 minute file might time 4 hours.<jupyter_code>data_root = 'data/speech'
sphinx_model_root = 'model' # point this to the folder called "model"
from os import environ, path
from os.path import join
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *
from tqdm import tqdm
from utils import *
import librosa
import os
import numpy as np
config = Decoder.default_config()
config.set_string('-hmm', join(sphinx_model_root, 'en-us/en-us/'))
config.set_string('-allphone', join(sphinx_model_root, 'en-us/en-us-phone.lm.bin'))
decoder = Decoder(config)
stream = open(join(data_root, 'raw/audio.wav'))
total = os.fstat(stream.fileno()).st_size
pbar = tqdm(total=total)
buf_size = 1024
decoder.start_utt()
while True:
    buf = stream.read(buf_size)
    pbar.update(buf_size)
    if buf:
        decoder.process_raw(buf, False, False)
    else:
        break
decoder.end_utt()
y, sr = librosa.load(fn, sr=16000)
frame_size = len(y) / decoder.n_frames()
print frame_size
for i, seg in enumerate(tqdm(decoder.seg(), leave=True)):
    start_sample = frame_size * seg.start_frame
    stop_sample = frame_size * seg.end_frame
    cur = y[start_sample:stop_sample]
    ffmpeg_save_audio(join(data_root, 'samples/{}.wav'.format(i)), cur, sr=sr)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10921717171717171, 'fraction_numerical': 0.00946969696969697, 'mean_word_length': 5.003787878787879, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '438913', 'license': 'MIT', 'n_tokens_mistral': 574, 'n_tokens_neox': 546, 'n_words': 152, 'path': 'Sphinx to Samples.ipynb', 'repo_name': 'prakilambi/AudioNotebooks', 'size': '1584'}