Spaces:
Runtime error
Runtime error
# Import libraries | |
import io | |
import os | |
import json | |
import subprocess | |
import mmap | |
import numpy | |
import soundfile | |
import torchaudio | |
import torch | |
import gradio as gr | |
from collections import defaultdict | |
from pathlib import Path | |
from pydub import AudioSegment | |
from seamless_communication.inference import Translator | |
from seamless_communication.streaming.dataloaders.s2tt import SileroVADSilenceRemover | |
# Mapping of language names to their respective codes | |
language_codes = { | |
"English": "eng", | |
"Spanish": "spa", | |
"French": "fra", | |
"German": "deu", | |
"Italian": "ita", | |
"Chinese": "cmn" | |
} | |
# Function to handle the translation to target language | |
def translate_audio(audio_file, target_language): | |
language_code = language_codes[target_language] | |
output_file = "translated_audio.wav" | |
command = f"expressivity_predict {audio_file} --tgt_lang {language_code} \ | |
--model_name seamless_expressivity --vocoder_name vocoder_pretssel \ | |
--gated-model-dir seamlessmodel --output_path {output_file}" | |
subprocess.run(command, shell=True) | |
if os.path.exists(output_file): | |
print(f"File created successfully: {output_file}") | |
else: | |
print(f"File not found: {output_file}") | |
return output_file | |
# Define inputs | |
inputs = [ | |
gr.Audio(type = "filepath", label = "Audio_file"), | |
gr.Dropdown(["English", "Spanish", "French", "German", "Italian", "Chinese"], label = "Target_Language") | |
] | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=translate_audio, | |
inputs= inputs, | |
outputs=gr.Audio(label="Translated Audio"), | |
title="Seamless Expressive Audio Translator", | |
description="Translate your audio into different languages with expressive styles." | |
) | |
# Run the application | |
if __name__ == "__main__": | |
iface.launch() |