File size: 1,272 Bytes
2355a75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
from speechbrain.pretrained.interfaces import foreign_class
import gradio as gr
import os
import warnings
warnings.filterwarnings("ignore")

# ... [rest of your code remains unchanged] ...

# Get the list of audio files for the dropdown
audio_files_list = get_audio_files_list()

# Function to return the selected audio file path
def get_audio_file_path(selected_audio):
    file_path = os.path.join("rec", selected_audio)
    return file_path

# Gradio components
dropdown = gr.Dropdown(label="Select Audio", choices=audio_files_list)
audio_player = gr.Audio(source="file", label="Listen to the selected audio")

# Update the audio player when a new selection is made from the dropdown
def update_audio(selected_audio):
    return get_audio_file_path(selected_audio)

# Connect the dropdown to the audio player using the update_audio function
dropdown.change(fn=update_audio, inputs=dropdown, outputs=audio_player)

# Update the Gradio interface to use both the dropdown and the audio player as inputs
interface = gr.Interface(
    fn=predict_emotion,
    inputs=[dropdown, audio_player],
    outputs="text",
    title="ML Speech Emotion Detection",
    description="Speechbrain powered wav2vec 2.0 pretrained model on IEMOCAP dataset using Gradio."
)

interface.launch()