unified soprano to rvc script

This commit is contained in:
2026-01-13 00:20:55 +02:00
parent 5eedbb80e4
commit 346f9ccbda
4 changed files with 469 additions and 2 deletions

View File

@@ -9,8 +9,17 @@ import os
import sys
import json
import argparse
import logging
import atexit
from pathlib import Path
# Set up logging
logging.basicConfig(
level=logging.INFO,
format='%(levelname)s: %(message)s'
)
logger = logging.getLogger(__name__)
# Set up environment (same as GUI)
os.environ["OMP_NUM_THREADS"] = "4"
if sys.platform == "darwin":
@@ -41,6 +50,7 @@ from configs.config import Config
inp_q = Queue()
opt_q = Queue()
n_cpu = min(cpu_count(), 8)
harvest_processes = [] # Keep track of processes for cleanup
class Harvest(multiprocessing.Process):
@@ -71,6 +81,23 @@ for _ in range(n_cpu):
p = Harvest(inp_q, opt_q)
p.daemon = True
p.start()
harvest_processes.append(p)
def cleanup_harvest_processes():
"""Terminate all harvest processes gracefully"""
global harvest_processes
for p in harvest_processes:
if p.is_alive():
p.terminate()
# Wait briefly for processes to terminate
for p in harvest_processes:
p.join(timeout=0.1)
harvest_processes.clear()
# Register cleanup to run on exit
atexit.register(cleanup_harvest_processes)
def phase_vocoder(a, b, fade_out, fade_in):
@@ -344,7 +371,6 @@ class HeadlessRVC:
self.input_wav[:-self.block_frame] = self.input_wav[self.block_frame:].clone()
self.input_wav[-indata.shape[0]:] = torch.from_numpy(indata).to(self.config.device)
self.input_wav_res[:-self.block_frame_16k] = self.input_wav_res[self.block_frame_16k:].clone()
# Input noise reduction
if self.gui_config.I_noise_reduce:
@@ -458,7 +484,7 @@ class HeadlessRVC:
)
total_time = time.perf_counter() - start_time
print(f"Infer time: {total_time:.2f}s")
logger.debug(f"Infer time: {total_time:.2f}s")
finally:
# Restore directory
@@ -500,6 +526,9 @@ class HeadlessRVC:
self.stream.abort()
self.stream.close()
self.stream = None
# Clean up harvest processes
cleanup_harvest_processes()
print("✓ Audio stream stopped")