-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path03_03e.txt
34 lines (23 loc) · 1.06 KB
/
03_03e.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Please run this in your Google Colab Environment
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
import torch
import torchaudio
import re
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-base-960h")
audio_file = "audio.wav"
waveform, sample_rate = torchaudio.load(audio_file)
resampler = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000)
waveform = resampler(waveform)
inputs = processor(waveform.squeeze(), sampling_rate=16000, return_tensors="pt", padding=True)
with torch.no_grad():
logits = model(inputs.input_values).logits
predicted_ids = torch.argmax(logits, dim=-1)
transcription = processor.decode(predicted_ids[0])
print(transcription)
def clean_transcription(text):
filler_words = ["A", "YOU KNOW", "AM", "BASICALLY", "LIKE", "SO YA"]
pattern = r"\b(" + "|".join(filler_words) + r")\b"
return re.sub(pattern, "", text)
refined_transcription = clean_transcription(transcription)
print(refined_transcription)