from transformers import AutoTokenizer, AutoModelForSeq2SeqLM from transformers import MarianMTModel, MarianTokenizer from elevenlabs import set_api_key from elevenlabs import clone, generate, play from transformers import AutoModelForSeq2SeqLM, AutoTokenizer from pydub import AudioSegment from huggingface_hub.hf_api import HfFolder HfFolder.save_token('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') access_token = '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' import streamlit as st #language translation function def translate_english_to_hindi(input_text): # Load the pre-trained English to Hindi translation model and tokenizer model_name = "Helsinki-NLP/opus-mt-en-hi" tokenizer = MarianTokenizer.from_pretrained(model_name) model = MarianMTModel.from_pretrained(model_name) # Tokenize the input text and generate translation inputs = tokenizer(input_text, return_tensors="pt", padding=True) translated_ids = model.generate(inputs.input_ids) # Decode the translated output translated_text = tokenizer.decode(translated_ids[0], skip_special_tokens=True) return translated_text def save_uploaded_file_as_mp3(uploaded_file, output_file_path): audio = AudioSegment.from_file(uploaded_file) audio.export(output_file_path, format="mp3") def ui(): st.title('Multi Lingual Voice Cloner') st.markdown("Made by vageesh") #audio input box audio_file = st.file_uploader("Upload an audio file that needs to be cloned", type=[ "wav,Mp4","Mp3"]) if audio_file is not None: output_file_path = "./output_audio.mp3" save_uploaded_file_as_mp3(audio_file, output_file_path) st.success(f"Audio file saved as {output_file_path}") user_api_key = st.sidebar.text_input( label="#### Your Eleven Labs API key here 👇", placeholder="Paste your Eleven Labs API key API key, sk-", type="password") if user_api_key is not None and user_api_key.strip() != "": set_api_key(user_api_key) #making an voice voice = clone( name="Alex", description="An middle aged American male voice with a slight hoarseness in his throat. Perfect for npodcast", # Optional files=["./output_audio.mp3"], model='eleven_multilingual_v1', language='Hindi' ) in_text=st.text_input("Paste the text you want to hear from english to hindi") if in_text is not None and in_text.strip() != "": hin_text=translate(in_text) audio = generate(text=hin_text, voice=voice) st.audio(audio) if __name__=="__main__": ui()