Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API conventions #34

Open
iranroman opened this issue Jan 22, 2024 · 2 comments
Open

API conventions #34

iranroman opened this issue Jan 22, 2024 · 2 comments
Assignees

Comments

@iranroman
Copy link
Owner

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)    
@iranroman iranroman self-assigned this Jan 22, 2024
@ChrisIck
Copy link
Collaborator

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
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants