Skip to content

Commit c7a5963

Browse files
committed
change harvest_frq to not multithread by default
it's just safer to run it without threading! also fixed a print issue cuz i forgor to add an f before the string
1 parent c1e5460 commit c7a5963

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ This script requires numpy, soundfile, and pyworld to be installed in your Pytho
120120
This script generates `.frq` files using the Harvest F0 estimation algorithm from WORLD. It uses Python's multiprocessing module to speed up the process of generating `.frq` files. This script is definitely not restricted to usage for NNSVS only, as you can use it to make `.frq` files for your UTAU voicebanks as well. You may also drag and drop the folder over the script file to run it, or use the terminal to run it.
121121

122122
```
123-
usage: harvest_frq.exe [-h] [--single-thread] [--num-threads NUM_THREADS] path
123+
usage: harvest_frq.exe [-h] [--num-threads NUM_THREADS] path
124124
125125
Generate .frq files using WORLD's Harvest F0 estimation algorithm.
126126
@@ -129,17 +129,21 @@ positional arguments:
129129
130130
optional arguments:
131131
-h, --help show this help message and exit
132-
--single-thread, -s Run single threaded
133132
--num-threads NUM_THREADS, -n NUM_THREADS
134-
How many threads to use. Default is a third of your thread count.
133+
How many threads to use. Default is running single threaded. Input zero to use all available
134+
threads.
135135
```
136136

137137
This script also requires numpy, pyworld and soundfile.
138138

139+
**WARNING:** It seems to be generally safer to run `harvest_frq` without threading, as Harvest itself is quite CPU-intensive. If you think you can run it with multiple threads you may do it, but remember that ***you are willingly putting your computer at risk by doing so.***
140+
139141
**UPDATE 12/13/2022:** Made this script support making a `.frq` file for a single `.wav` file through the same drag and drop behavior.
140142

141143
**UPDATE 06/14/2023:** Added an optional argument to limit the number of threads used and switched to `soundfile` for reading `.wav` files.
142144

145+
**UPDATE 06/21/2023:** Default to running without threading. Read warning as to why.
146+
143147
### threaded_noise_remove.py
144148

145149
This script uses the Log-MMSE algorithm to denoise all `.wav` files in a folder, including its subfolders. It assumes that the first 120ms of each sample is noise. Performance is also dependent on the noise type as this is still an algorithmic noise remover.
@@ -162,6 +166,8 @@ optional arguments:
162166

163167
This script requires numpy, scipy and soundfile. The Log-MMSE implementation is a direct translation of [this MATLAB code](https://raw.githubusercontent.com/braindead/Noise-reduction/master/logmmse.m) into Python.
164168

169+
**Slight WARNING:** `threaded_noise_remove` seems to be quite safe even with threading, but please do check if your CPU can handle it.
170+
165171
**UPDATE 12/13/2022:** Made this script support denoising a single `.wav` file through the same drag and drop behavior.
166172

167173
**UPDATE 06/14/2023:** Added an optional argument to limit the number of threads used and switched to `soundfile` for dealing with `.wav` files.

harvest_frq.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,19 @@ def process_directory(args):
8282
fname, _ = os.path.splitext(file)
8383
samples.append(os.path.join(root, file))
8484
logging.info(f'Listed {len(samples)} file{"s" if len(samples) != 1 else ""}')
85-
86-
if args.single_thread or args.num_threads == 1:
85+
86+
num_threads = max(0, args.num_threads)
87+
if num_threads == 1:
8788
logging.info('Running single threaded')
8889
t0 = time.perf_counter()
8990
for sample in samples:
9091
frq_gen(sample)
9192
t = time.perf_counter()
9293
else:
93-
logging.info('Starting process pool with {args.num_threads} threads.')
94+
workers = os.cpu_count if num_threads == 0 else num_threads
95+
logging.info(f'Starting process pool with {workers} threads.')
9496
t0 = time.perf_counter()
95-
with concurrent.futures.ProcessPoolExecutor(max_workers=args.num_threads) as executor:
97+
with concurrent.futures.ProcessPoolExecutor(max_workers=workers) as executor:
9698
executor.map(frq_gen, samples)
9799
t = time.perf_counter()
98100
logging.info(f'Whole operation took {t - t0:.3f} seconds.')
@@ -102,8 +104,7 @@ def process_directory(args):
102104
try:
103105
parser = ArgumentParser(description="Generate .frq files using WORLD's Harvest F0 estimation algorithm.")
104106
parser.add_argument('path', help='The path to a .wav file or a directory with .wav files.')
105-
parser.add_argument('--single-thread', '-s', action='store_true', help='Run single threaded')
106-
parser.add_argument('--num-threads', '-n', type=int, default=os.cpu_count() // 3, help='How many threads to use. Default is a third of your thread count.')
107+
parser.add_argument('--num-threads', '-n', type=int, default=1, help='How many threads to use. Default is running single threaded. Input zero to use all available threads.')
107108

108109
args, _ = parser.parse_known_args()
109110
if os.path.isfile(args.path):

threaded_noise_remove.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def process_directory(args):
138138
remove_noise(sample)
139139
t = time.perf_counter()
140140
else:
141-
logging.info('Starting process pool with {args.num_threads} threads.')
141+
logging.info(f'Starting process pool with {args.num_threads} threads.')
142142
t0 = time.perf_counter()
143143
with concurrent.futures.ProcessPoolExecutor(max_workers=args.num_threads) as executor:
144144
executor.map(remove_noise, samples)

0 commit comments

Comments
 (0)