Spaces:
Runtime error
Runtime error
| # -*- coding: utf-8 -*- | |
| import crepe | |
| import librosa | |
| import gradio as gr | |
| import pandas as pd | |
| from transformers import pipeline, RobertaTokenizerFast, TFRobertaForSequenceClassification | |
| asr = pipeline('automatic-speech-recognition', model='facebook/wav2vec2-large-960h-lv60-self') | |
| tokenizer = RobertaTokenizerFast.from_pretrained("arpanghoshal/EmoRoBERTa") | |
| model = TFRobertaForSequenceClassification.from_pretrained("arpanghoshal/EmoRoBERTa") | |
| emo = pipeline('sentiment-analysis', model='arpanghoshal/EmoRoBERTa') | |
| pos = pipeline("token-classification", model="vblagoje/bert-english-uncased-finetuned-pos") | |
| def transcribe_and_describe(audio): | |
| audio, sr = librosa.load(audio, sr=16000) | |
| text = asr(audio)['text'] | |
| tagged_text = pos(text) | |
| filler_words = [entry['word'] for entry in tagged_text if entry['entity'] == 'INTJ'] | |
| filler_word_pr = len(filler_words) / len(tagged_text) | |
| flatness = pd.DataFrame(librosa.feature.spectral_flatness(y=audio).T).describe().T | |
| loudness = pd.DataFrame(librosa.feature.rms(audio).T).describe().T | |
| time, frequency, confidence, activation = crepe.predict(audio, sr) | |
| frequency = pd.DataFrame(frequency.T).describe().T | |
| mean_spectral_flatness = flatness.loc[0, 'mean'] | |
| spectral_flatness_std = flatness.loc[0, 'std'] | |
| mean_pitch = frequency.loc[0, 'mean'] | |
| pitch_std = frequency.loc[0, 'std'] | |
| mean_volume = loudness.loc[0, 'mean'] | |
| volume_std = loudness.loc[0, 'std'] | |
| words_per_minute = len(text.split(" ")) / (librosa.get_duration(audio, sr) / 60) | |
| emotion = emo(text)[0]['label'] | |
| return (text, f"{filler_word_pr:.2f}", f"{words_per_minute:.2f}", f"{mean_pitch:.2f}", f"{pitch_std:.2f}", f"{mean_volume:.2f}", f"{volume_std:.2f}", f"{mean_spectral_flatness:.2f}", f"{spectral_flatness_std:.2f}", emotion) | |
| gr.Interface( | |
| fn=transcribe_and_describe, | |
| inputs=gr.Audio(source="microphone", type="filepath"), | |
| outputs=[ | |
| gr.Text(label="Transcription"), | |
| gr.Text(label="Filler Word Percent"), | |
| gr.Text(label="Rate of Speech (WPM)"), | |
| gr.Text(label="Mean Pitch (Hz)"), | |
| gr.Text(label="Pitch Variation (Hz)"), | |
| gr.Text(label="Mean Volume (W)"), | |
| gr.Text(label="Volume Variation (W)"), | |
| gr.Text(label="Mean Spectral Flatness (dB)"), | |
| gr.Text(label="Spectral Flatness Variation (dB)"), | |
| gr.Text(label="Emotion") | |
| ] | |
| ).launch() | |