Sample code for voice transformation #370
Replies: 3 comments
-
Yes, it is possible to use OpenVoice 2 to transform the message in from openvoice.api import OpenVoice
# Initialize OpenVoice with necessary parameters
openvoice = OpenVoice()
# Define source and target speaker embeddings
src_se = 'path_to_source_speaker_embedding' # Replace with actual path or embedding
tgt_se = 'path_to_target_speaker_embedding' # Replace with actual path or embedding
# Convert the message in message.wav to have the voice of voice.wav
output_audio = openvoice.convert(
audio_src_path='message.wav',
src_se=src_se,
tgt_se=tgt_se,
output_path='output_message.wav',
tau=0.3,
message="default"
)
# The converted audio will be saved to 'output_message.wav' Make sure to replace To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
-
can you please provide the whole code ? |
Beta Was this translation helpful? Give feedback.
-
I get the following error with this code ImportError: cannot import name 'OpenVoice' from 'openvoice.api'` |
Beta Was this translation helpful? Give feedback.
-
Hello,
let's say I have 2 audio files : f1.wav and f2.wav
I'd like to generate a new audio file f3.wav that contains the message in f1.wav but with the voice of f2.wav.
Is this possible with openvoice 2 ?
If yes can you please post a sample code ?
Also is it possible to use this with french messages and voices ?
Thanks for help.
PS: an AI tool helped me to generate the following code which works but the generated voice has no link with the voice I provided. It's a female voice while my target voice is a male voice. Furthermore, the generated message is read by an english speech synthesis while the original message is in french. I tried to change the language of the speech synthesis but it doesn't recognize french.
import torch
import numpy as np
from openvoice import se_extractor
from openvoice.api import BaseSpeakerTTS, ToneColorConverter
def clone_voice_en(f1_path, f2_path, output_path='f3.wav'):
# 1. Initialisation des modèles
checkpoint = 'C:/Users/me/Desktop/OV/openvoice/checkpoints/base_speakers/EN'
config_path = f'{checkpoint}/config.json'
model_path = f'{checkpoint}/checkpoint.pth'
device = "cuda" if torch.cuda.is_available() else "cpu"
def extract_text_from_audio_en(audio_path):
"""Utilisation de Whisper pour la transcription"""
import whisper
model = whisper.load_model("base")
result = model.transcribe(audio_path, language="fr")
return result["text"]
if name == "main":
clone_voice_en("f1.wav", "f2.wav", "f3.wav")
Beta Was this translation helpful? Give feedback.
All reactions