Skip to content

Commit

Permalink
Adds parameter --voice-name for keypress recording only
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMaakarov committed Jun 8, 2023
1 parent c871a8f commit 1d5f26e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions scripts/recording_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pydub import AudioSegment
from scipy.signal import resample
from tqdm import tqdm
import os
import sounddevice as sd
import soundfile as sf

Expand All @@ -19,13 +20,13 @@ def countdown(count: int):
time.sleep(0.001)

def record_until_keypress(
output_folder: str,
voice_name: str,
samplerate: int=22050,
channels: int=1):
"""Record audio in chunks until interrupted, then chop into 10s fragments.
Args:
output_folder (str): Path to the voice folder where the chunks will be saved.
voice_name (str): The name of the voice that records.
samplerate (int, optional): Target sample rate. Defaults to 22050.
channels (int, optional): The number of channels (1=mono, 2=stereo). Defaults to 1.
"""
Expand All @@ -34,14 +35,19 @@ def record_until_keypress(
i=0
try:
while True:
recording =sd.rec(
recording = sd.rec(
int(samplerate * DURATION), samplerate=samplerate, channels=channels, blocking=True)
i+=1
print(f"Chunk #{i} was recorded")
recordings.append(recording)
except KeyboardInterrupt:
print("Recording stopped.")

output_folder = f'../tortoise/voices/{voice_name}/'
try:
os.mkdir(output_folder)
except FileExistsError:
pass
for i, rec in enumerate(recordings):
fname = f'{output_folder}/{i+1}.wav'
try:
Expand Down Expand Up @@ -124,6 +130,9 @@ def chop_audio(input_path: str,
parser.add_argument(
'--file_path',
help='Path to the file to process')
parser.add_argument(
'--voice_name',
help='The name of the voice that will record')
parser.add_argument(
'--output_folder',
help='Folder to save the chunks')
Expand All @@ -141,6 +150,7 @@ def chop_audio(input_path: str,
help='Seconds between recordings')

args = parser.parse_args()
print(args.no_convert)

if args.command == 'record':
record_audio(
Expand All @@ -153,4 +163,4 @@ def chop_audio(input_path: str,
args.output_folder,
no_conversion=args.no_convert)
elif args.command == 'keypress':
record_until_keypress(args.file_path)
record_until_keypress(args.voice_name)

0 comments on commit 1d5f26e

Please sign in to comment.