iranroman / SpatialScaper

Creative Commons Attribution 4.0 International
17 stars 4 forks source link

API conventions #34

Open iranroman opened 5 months ago

iranroman commented 5 months ago

API version 0.1.0 proposes an API #31 that resembles Scaper but with the spatial functionalities added. Here is an example script:

import numpy as np 
import spatialscaper as ss
import os

# Constants
NSCAPES = 25
FOREGROUND_DIR = "datasets/sound_event_datasets/FSD50K_FMA" 
BACKGROUND_DIR = ""                                                               
RIR_DIR = "datasets/rir_datasets"                                                 
ROOM = "metu"                                                                     
FORMAT = "mic"                                                                    
MIN_EVENTS = 3                                                                    
MAX_EVENTS = 8                                                                    
DURATION = 60.0  # Duration in seconds                                            
SR = 24000  # Sampling rate                                                       
OUTPUT_DIR = "output"                                                             
REF_DB = -65  # Reference decibel level                                           

# Function to generate a soundscape                                               
def generate_soundscape(index):                                                   
    track_name = f"fold5_room1_mix00{index + 1}"                                  
    ssc = ss.Scaper(                                                              
        DURATION, FOREGROUND_DIR, BACKGROUND_DIR, RIR_DIR, ROOM, FORMAT, SR       
    )                                                                             
    ssc.ref_db = REF_DB                                                           

    # Add background                                                              
    ssc.add_background()                                                          

    # Add a random number of foreground events                                    
    n_events = np.random.randint(MIN_EVENTS, MAX_EVENTS + 1)                      
    for _ in range(n_events):                                                     
        ssc.add_event(event_position=("moving", ("uniform", None, None)))         

    audiofile = os.path.join(OUTPUT_DIR, FORMAT, track_name)                      
    labelfile = os.path.join(OUTPUT_DIR, "labels", track_name)                    

    ssc.generate(audiofile, labelfile)                                            

# Main loop for generating soundscapes                                            
for iscape in range(NSCAPES):                                                     
    print(f"Generating soundscape: {iscape + 1}/{NSCAPES}")                       
    generate_soundscape(iscape)    
ChrisIck commented 5 months ago

Can we better define this task? Speccing out the API scope is important and I'm not sure it's been explicitly done (at least, in a way that allows us to all be aware of what's in-dev/needs to be worked on). Might be useful to write out an API roadmap to see where we're at.

iranroman commented 3 months ago

52 and #43 are steps toward defining the API conventions. We can continue using this issue to discuss conventions moving forward.