Skip to content

added CPU support to se_extractor.py #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions openvoice/se_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
import librosa
from whisper_timestamped.transcribe import get_audio_tensor, get_vad_segments

# Check if CUDA is available and use it if so, otherwise use CPU
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using device: {device}")

model_size = "medium"
# Run on GPU with FP16
# Run on GPU with FP16 if CUDA is available, otherwise use CPU with FP32
model = None

def split_audio_whisper(audio_path, audio_name, target_dir='processed'):
global model
if model is None:
model = WhisperModel(model_size, device="cuda", compute_type="float16")
model = WhisperModel(model_size, device=device, compute_type="float16" if device == "cuda" else "float32")
audio = AudioSegment.from_file(audio_path)
max_len = len(audio)

Expand Down Expand Up @@ -150,4 +155,3 @@ def get_se(audio_path, vc_model, target_dir='processed', vad=True):
raise NotImplementedError('No audio segments found!')

return vc_model.extract_se(audio_segs, se_save_path=se_path), audio_name