<jupyter_start><jupyter_text>Table of Contents1&nbsp;&nbsp;Import time signal1.1&nbsp;&nbsp;Steady signal from a .wav file1.2&nbsp;&nbsp;Steady signal from a .mat file1.3&nbsp;&nbsp;Time-varying signal from a .uff file2&nbsp;&nbsp;Plot time signal3&nbsp;&nbsp;Third-octave spectrum4&nbsp;&nbsp;Overall level  Audio signal basic operationsThis tutorial explains how to use MOSQITO scripting interface to realise various basic operations from an audio signal. Users that just need to compute SQ metrics should preferably use this scripting interface approach.  Import time signalThe creation of an Audio object is done by importing an audio file. Three arguments are needed : - the file path, - an amplification factor. It shall be equal to 1 if the imported signal is already in Pascal. In some cases (while working with .wav files, for instance) the original signal in Pa, of amplitude A, is scaled to A/factor before being exported. When using the present function with such file, the factor shall be defined as input parameter (calib=factor) to be able to scale the signal back to Pascal. Default is set to 1. - a boolean to indicate either the signal is stationary (True) or time-varying (False). Default is set to False. - (in the specific case of a .mat file, 2 other arguments are needed to indicate the keys of the signal and the sampling frequency)The function automatically detects the file type. In the following command lines, three different signals are imported into three different audio objects. Steady signal from a .wav file<jupyter_code># Add MOSQITO to the Python path
import sys
sys.path.append('..')

%matplotlib notebook

# Import Audio class
from mosqito.classes.Audio import Audio

# Create an Audio object
signal_from_wav = Audio(
    "../validations/loudness_zwicker/data/ISO_532-1/Test signal 5 (pinknoise 60 dB).wav",
    calib=2 * 2 ** 0.5,
    is_stationary=True,
)<jupyter_output><empty_output><jupyter_text>Steady signal from a .mat fileIn the case of a .mat file, it is necessary to give the keys corresponding to the signal and the sampling frequency so that the function reads the correct values in the file.<jupyter_code># Create a new Audio object
signal_from_mat = Audio(
     "noise_1Pa_RMS.mat",
     is_stationary=True,
     mat_signal="signal",
     mat_fs="fs"
)<jupyter_output>[Info] Signal resampled to 48 kHz to allow calculation.<jupyter_text>Time-varying signal from a .uff file<jupyter_code># Create another Audio object
signal_from_uff = Audio(
    "noise_1Pa_RMS.uff",
    is_stationary=True,
)<jupyter_output>[Info] Signal resampled to 48 kHz to allow calculation.<jupyter_text>Plot time signalAn Audio object is created by importing an audio file. In this example, the signal is imported from a .wav file.<jupyter_code># Add MOSQITO to the Python path
import sys
sys.path.append('..')

# Import MOSQITO color sheme [Optional]
from mosqito import COLORS

# Import Audio class
from mosqito.classes.Audio import Audio

# Create an Audio object
woodpecker = Audio(
    "../validations/loudness_zwicker/data/ISO_532-1/Annex B.5/Test signal 24 (woodpecker).wav",
    calib=2 * 2 ** 0.5,
)<jupyter_output><empty_output><jupyter_text>Once the audio signal has been imported, the following command line makes a plot over time of the acoustic signal amplitude.<jupyter_code>%matplotlib notebook
# Plot time signal
woodpecker.signal.plot_2D_Data(
    "time",
    type_plot="curve",
    color_list=COLORS,
)<jupyter_output><empty_output><jupyter_text>Third-octave spectrumAn Audio object is created by importing an audio file. In this example, the signal is imported from a .wav file.<jupyter_code># Add MOSQITO to the Python path
import sys
sys.path.append('..')

# Import MOSQITO color sheme [Optional]
from mosqito import COLORS

# Import Audio class
from mosqito.classes.Audio import Audio

# Create an Audio object
pink_noise = Audio(
    "../validations/loudness_zwicker/data/ISO_532-1/PinkNoise_40dBpHz@1000Hz.wav",
    calib=2 * 2 ** 0.5,
    is_stationary=False
)

# Compute third-octave spectrum
pink_noise.comp_3oct_spec()<jupyter_output><empty_output><jupyter_text>The preceeding command line launched the computation of the third-octave spectrum that is now stored in the woodpecker object. The following command shows how to plot the spectrum. The argument "freqs" indicates the axis along which to plot, and the "time=1" takes the spectrum at 1 second. The optional type_plot argument is obviously used to specifies the plot type (among "curve", "bargraph", "barchart" and "quiver"). The optional color_list argument is used to specify the color scheme used for the plots.<jupyter_code># Plot third-octave spectrum
pink_noise.third_spec.plot_2D_Data(
        "freqs",
        "time=1",
        type_plot="octave",
        is_logscale_x=True,
        x_min=20,
        y_min=0,
        unit="dB",
        color_list=COLORS
    )<jupyter_output><empty_output><jupyter_text>Overall levelAn Audio object is created by importing an audio file. In this example, the signal is imported from a .wav file.<jupyter_code># Add MOSQITO to the Python path
import sys
sys.path.append('..')

# Import MOSQITO color sheme [Optional]
from mosqito import COLORS

# Import Audio class
from mosqito.classes.Audio import Audio

# Create an Audio object
woodpecker = Audio(
    "../validations/loudness_zwicker/data/ISO_532-1/Annex B.5/Test signal 24 (woodpecker).wav",
    calib=2 * 2 ** 0.5,
)<jupyter_output><empty_output><jupyter_text>The following command line launches the computation of the overall sound pressure level, with 3 arguments: - nb_points: the number of points, i.e. the number of level values, - start: the beginning of the time frame of interest (in s) - stop: the end of the time frame of interest (in s)The next command shows how to plot the spectrum.The argument "time" indicates that the level values should be plotted along the time axis. The optional type_plot argument is obviously used to specifies the plot type (among "curve", "bargraph", "barchart" and "quiver"). The optional color_list argument is used to specify the color scheme used for the plots.<jupyter_code># Compute overall level
woodpecker.compute_level(nb_points=10,start=0.5,stop=1.5)

# Plot SPL
woodpecker.level.plot_2D_Data(
    "time",
    type_plot="curve",
    color_list=COLORS,
)<jupyter_output><empty_output><jupyter_text>---<jupyter_code>from datetime import date
print("Tutorial generation date:", date.today().strftime("%B %d, %Y"))<jupyter_output>Tutorial generation date: February 15, 2022
{'fraction_non_alphanumeric': 0.07960808328230251, 'fraction_numerical': 0.013625229638701776, 'mean_word_length': 4.761022927689594, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '174448', 'license': 'Apache-2.0', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1937, 'n_words': 772, 'path': 'tutorials/tuto_signal_basic_operations.ipynb', 'repo_name': 'TutorialMaker/MoSQITo', 'size': '6532'}