#!/usr/bin/env python3 # This script helps you sorting good-quality voice-lines from low-quality for training. # It plays the voice lines in *TWICE THE SPEED* to speed up this process (still takes hours) - This will make the voices sound like chipmunk voices. That is fine. # Have the folowing folders prepared in respect to this repository # raw # - p1: Portal1 voice lines # - p2: Portal2 voice lines # - p2dlc: Portal 2 voice lines (if available) # raw_good: Destination folder for good voice lines # raw_bad: Destination folder for bad voice lines # Start this program (linux: start a terminal an run it via ./0_sort_good_bad.py) # Press left/right *ONCE* to play the first voice line (in twice the speed - aka chipmunk voice) # - If it is good: press RIGHT ARROW # - If it was bad: press LEFT ARROW # - If you want to replay it (or check it without chipmunk effect): press UP arrow # Get some coffee. This might take a few hours, even though we play the voice lines at twice the speed import os import wave import pyaudio import tkinter as tk import shutil import os from pathlib import Path def play_wav_file(file_path, speed = 1): """Play a WAV file.""" with wave.open(file_path, 'rb') as wf: p = pyaudio.PyAudio() # Set audio stream parameters stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), channels=wf.getnchannels(), rate=int(wf.getframerate() * speed), # Double the speed output=True) data = wf.readframes(1024) while data: stream.write(data) data = wf.readframes(1024) stream.stop_stream() stream.close() p.terminate() def find_wav_files(directory): """Recursively find all WAV files in a directory.""" wav_files = [] for root, _, files in os.walk(directory): for file in files: if file.endswith('.wav'): wav_files.append(os.path.join(root, file)) return wav_files pos = 0 files = [] wav = "" def play(speed = 1.5): global pos, files, wav wav = files[pos] print(f"File: {wav}") play_wav_file(wav, speed) pos += 1 print("---> ?") def move(src, dst): src = Path(src) #dst_name = Path(dst) / f"{src.parent.name}_{src.name}" # I used to prepepend the parent folders (p1, p2, p2dlc) as I was unsure, if the files have unique names across games. They indeed are unique -> Disabled dst_name = Path(dst) / src.name shutil.move(src, dst_name) def on_key_press(event): global pos, files, wav if pos >= len(files): print("FINISHED") if pos == 0: return play() speed = 1.5 if event.keysym == 'Left': print("No") print("--------------------------------------") move(wav, "raw_bad") elif event.keysym == 'Right': print("Yes") print("--------------------------------------") move(wav, "raw_good") else: speed = 1 pos -= 1 if pos < 0: pose = 0 play(speed) if __name__ == "__main__": src = "./raw/" files = find_wav_files(src) root = tk.Tk() root.title("Left: Discard, Right: Match, Up: Replay normal (no Chipmunk)") root.geometry("300x150") root.bind("", on_key_press) root.mainloop()