<jupyter_start><jupyter_text>Vakyansh + Hugging Face : Indian English Speech To text Demo---  Install requirements<jupyter_code>%%capture

!apt-get -y install sox ffmpeg
!pip install transformers ffmpeg-python sox

!wget https://raw.githubusercontent.com/harveenchadha/bol/main/demos/colab/record.py<jupyter_output><empty_output><jupyter_text>Load Indian English Model<jupyter_code>import soundfile as sf
import torch
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor

def load_model():
    # load pretrained model
    processor = Wav2Vec2Processor.from_pretrained("Harveenchadha/vakyansh-wav2vec2-indian-english-enm-700")
    model = Wav2Vec2ForCTC.from_pretrained("Harveenchadha/vakyansh-wav2vec2-indian-english-enm-700")
    return processor, model

processor, model = load_model()

def parse_transcription(wav_file):
    # load audio    
    audio_input, sample_rate = sf.read(wav_file)

    # pad input values and return pt tensor
    input_values = processor(audio_input, sampling_rate=16_000, return_tensors="pt").input_values

    # INFERENCE
    # retrieve logits & take argmax
    logits = model(input_values).logits
    predicted_ids = torch.argmax(logits, dim=-1)

    # transcribe
    transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
    return transcription<jupyter_output><empty_output><jupyter_text>Record file using colab<jupyter_code>from record import record_audio

record_audio('test')<jupyter_output><empty_output><jupyter_text>Run Model on recorded file<jupyter_code>parse_transcription('test.wav')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09136735979836169, 'fraction_numerical': 0.01575299306868305, 'mean_word_length': 6.057777777777778, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '505108', 'license': 'MIT', 'n_tokens_mistral': 560, 'n_tokens_neox': 542, 'n_words': 96, 'path': 'demos/hf/english/hf_english_enm_700_demo.ipynb', 'repo_name': 'harveenchadha/bol', 'size': '1587'}