Spaces:
Runtime error
Runtime error
File size: 1,817 Bytes
83bd913 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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() |