Audiosys Module

sudio.audiosys.channel.shuffle3d_channels(arr)

Shuffles the channels of a 3D array and returns a flattened result.

Parameters: - arr (numpy.ndarray): Input 3D array of shape (frames, channels, samples_per_frame)

Returns: - numpy.ndarray: Flattened array with interleaved channels.

sudio.audiosys.channel.shuffle2d_channels(arr)

Shuffles the channels of a 2D array and returns a flattened result.

Parameters: - arr (numpy.ndarray): Input 2D array of shape (m, n), where m and n are dimensions.

Returns: - numpy.ndarray: Flattened array with shuffled channels.

sudio.audiosys.channel.get_channel_data(wav, ch_index=None, output='wave', out_wave_name='sound0')

Extracts a specific channel or all channels from a WAV file.

Parameters: - wav (wave.Wave_read): Input WAV file opened in read mode. - ch_index (int or None): Index of the channel to extract. If None, extracts all channels. - output (str): Output format, can be ‘array’, ‘wave’, or ‘frame’. - out_wave_name (str): Output WAV file name (used when output is ‘wave’).

Returns: - numpy.ndarray or bytes: Depending on the ‘output’ parameter.

  • If ‘array’, returns a NumPy array containing the extracted channel(s).

  • If ‘wave’, writes a new WAV file and returns None.

  • If ‘frame’, returns the raw frames as bytes.

Note: - The ‘wave’ output option writes a new WAV file if ‘ch_index’ is None (all channels), otherwise, it creates a mono WAV file.

sudio.audiosys.channel.set_channel_data(wav, ch_index, inp, inp_format='wave', output='wave', out_wave_name='sound0')

Sets the specified channel of a WAV file to a new signal.

Parameters: - wav (wave.Wave_write): Input WAV file opened in write mode. - ch_index (int): Index of the channel to set. - inp (numpy.ndarray, wave.Wave_read, or bytes): Input signal to set the channel.

  • If ‘wave.Wave_read’, it extracts the frames from the input wave file.

  • If ‘bytes’, it directly uses the input frames as bytes.

  • If ‘numpy.ndarray’, it assumes a mono signal.

  • inp_format (str): Format of the input signal (‘wave’, ‘frame’, or ‘array’).

  • output (str): Output format, can be ‘array’, ‘wave’, or ‘frame’.

  • out_wave_name (str): Output WAV file name (used when output is ‘wave’).

Returns: - numpy.ndarray, wave.Wave_read, or bytes: Depending on the ‘output’ parameter.

  • If ‘array’, returns a NumPy array containing the modified signal.

  • If ‘wave’, writes a new WAV file and returns the opened file.

  • If ‘frame’, returns the modified frames as bytes.

sudio.audiosys.channel.delete_channel(wav, ch_index, output='wave', out_wave_name='sound0')

Deletes a specified channel from a WAV file.

Parameters: - wav (wave.Wave_write): Input WAV file opened in write mode. - ch_index (int): Index of the channel to delete. - output (str): Output format, can be ‘array’, ‘wave’, or ‘frame’. - out_wave_name (str): Output WAV file name (used when output is ‘wave’).

Returns: - numpy.ndarray, wave.Wave_read, or bytes: Depending on the ‘output’ parameter.

  • If ‘array’, returns a NumPy array containing the modified signal.

  • If ‘wave’, writes a new WAV file and returns the opened file.

  • If ‘frame’, returns the modified frames as bytes.

Note: - The deleted channel is replaced with zeros.

sudio.audiosys.channel.get_mute_mode_data(nchannel, nperseg)
sudio.audiosys.channel.map_channels(in_data, in_channels, out_channels)

Map input audio channels to desired output channels.

Args: in_data (np.ndarray): Input audio data. in_channels (int): Number of input channels. out_channels (int): Number of desired output channels. data_chunk (int): Size of data chunk for processing.

Returns: np.ndarray: Processed audio data with desired number of channels.

sudio.audiosys.sync.synchronize_audio(rec, nchannels, sample_rate, sample_format_id, output_data='byte')

Synchronizes audio data with the specified parameters.

Parameters: - rec (dict): The input audio recording data. - nchannels (int): The desired number of channels. - sample_rate (int): The desired sample rate. - sample_format_id (int): The desired sample format ID. - output_data (str): Output data format, can be ‘byte’ or ‘ndarray’.

Returns: - dict: The synchronized audio recording data.

Notes: - This function performs channel adjustment, resampling, and sample format conversion. - The input rec dictionary is modified in-place.

Usage: `python new_rec = synchronize_audio(rec, nchannels=2, sample_rate=44100, sample_format_id=SampleFormat.SIGNED16.value) `

Parameters:
  • rec – The input audio recording data.

  • nchannels (int) – The desired number of channels.

  • sample_rate (int) – The desired sample rate.

  • sample_format_id (int) – The desired sample format ID.

  • output_data – Output data format, can be ‘byte’ or ‘ndarray’.

Return type:

dict

Returns:

The synchronized audio recording data.

sudio.audiosys.typeconversion.convert_array_type(arr, sample_format)

Convert the data type of a NumPy array based on the given SampleFormat.

Args: arr (np.ndarray): Input NumPy array sample_format (SampleFormat): Desired output format

Returns: np.ndarray: Converted NumPy array

sudio.audiosys.window.win_parser_mono(window, win_num)
sudio.audiosys.window.win_parser(window, win_num, nchannel)
sudio.audiosys.window.single_channel_windowing(data, windowing_buffer, window, nhop)
sudio.audiosys.window.multi_channel_windowing(data, windowing_buffer, window, nhop, nchannels)
sudio.audiosys.window.single_channel_overlap(data, overlap_buffer, nhop)
sudio.audiosys.window.multi_channel_overlap(data, overlap_buffer, nhop, nchannels)