code: def generateSamples(overwrite=False, samples_dir=None):
      if not samples_dir:
          from timeside import __file__ as ts_file
  
          ts_path = os.path.split(os.path.abspath(ts_file))[0]
          tests_dir = os.path.abspath(os.path.join(ts_path, "../tests"))
          if os.path.isdir(tests_dir):
              samples_dir = os.path.abspath(
                  os.path.join(tests_dir, "samples")
              )
              if not os.path.isdir(samples_dir):
                  os.makedirs(samples_dir)
          else:
              import tempfile
  
              samples_dir = tempfile.mkdtemp(suffix="ts_samples")
      else:
          if not os.path.isdir(samples_dir):
              os.makedirs(samples_dir)
  
      samples = dict()
  
      # --------- Sweeps ---------
  
      # sweep 44100 mono wav
      filename = "sweep_mono.wav"
      samplerate = 44100
      gst_audio_encoder = "wavenc"
      sweep_mono = SweepArray(duration=8, samplerate=samplerate)
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=sweep_mono,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      # sweep 44100 stereo wav
      sweep_stereo = sweep_mono & sweep_mono
      filename = "sweep.wav"
      gst_audio_encoder = "wavenc"
      sweep_mono = SweepArray(duration=8, samplerate=samplerate)
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=sweep_stereo,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      sweep_wav = ffmpeg.input(
          "/srv/lib/timeside/tests/samples/sweep.wav"
      )
  
      sweep_list = [
          ("sweep.mp3", 44100),
          ("sweep_96000.flac", 96000),
          ("sweep.flac", 44100),
          ("sweep.ogg", 44100),
          ("sweep_32000.wav", 32000),
      ]
  
      for filename, sample_rate in sweep_list:
          sample_file = os.path.join(samples_dir, filename)
          if not os.path.exists(sample_file):
              sweep = ffmpeg.output(
                  sweep_wav, sample_file, ar=sample_rate
              )
              ffmpeg.run(sweep)
          samples.update({filename: sample_file})
  
      """
      # sweep 44100 stereo mp3
      filename = 'sweep.mp3'
      gst_audio_encoder = ['lamemp3enc']
      sweep_mono = SweepArray(duration=8, samplerate=samplerate)
      sample_file = generate_sample_file(filename, samples_dir,
                                         gst_audio_encoder,
                                         sample_array=sweep_stereo,
                                         overwrite=overwrite)
      samples.update({filename: sample_file})
  
  
      #sweep 96000 stereo flac
      filename = 'sweep_96000.flac'
      samplerate = 96000
      gst_audio_encoder = 'wavenc'
      sweep_96000 = SweepArray(duration=8, samplerate=samplerate)
      sample_file = generate_sample_file(filename, samples_dir,
                                         gst_audio_encoder,
                                         sample_array=sweep_96000)
      samples.update({filename: sample_file})
  
  
      # sweep 44100 stereo flac
      filename = 'sweep.flac'
      gst_audio_encoder = 'flacenc'
      sweep_mono = SweepArray(duration=8, samplerate=samplerate)
      sample_file = generate_sample_file(filename, samples_dir,
                                         gst_audio_encoder,
                                         sample_array=sweep_stereo,
                                         overwrite=overwrite)
      samples.update({filename: sample_file})
  
      # sweep 44100 stereo ogg
      filename = 'sweep.ogg'
      gst_audio_encoder = ['vorbisenc', 'vorbisparse', 'oggmux']
      sweep_mono = SweepArray(duration=8, samplerate=samplerate)
      sample_file = generate_sample_file(filename, samples_dir,
                                         gst_audio_encoder,
                                         sample_array=sweep_stereo,
                                         overwrite=overwrite)
      samples.update({filename: sample_file})
  
      # sweep 32000 stereo wav
      samplerate = 32000
      sweep_mono = SweepArray(duration=8, samplerate=samplerate)
      sweep_stereo = sweep_mono & sweep_mono
  
      filename = 'sweep_32000.wav'
      gst_audio_encoder = 'wavenc'
      sweep_mono = SweepArray(duration=8, samplerate=samplerate)
      sample_file = generate_sample_file(filename, samples_dir,
                                         gst_audio_encoder,
                                         sample_array=sweep_stereo,
                                         overwrite=overwrite)
      samples.update({filename: sample_file})
      """
  
      # --------- Sines ---------
      # sine at 440Hz,  44100 mono wav
      filename = "sine440Hz_mono.wav"
      samplerate = 44100
      gst_audio_encoder = "wavenc"
      sweep_mono = SineArray(
          duration=8, samplerate=samplerate, frequency=440
      )
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=sweep_mono,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      # Short 1s sine at 440Hz,  44100 mono wav
      filename = "sine440Hz_mono_1s.wav"
      samplerate = 44100
      gst_audio_encoder = "wavenc"
      sweep_mono = SineArray(
          duration=1, samplerate=samplerate, frequency=440
      )
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=sweep_mono,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      # sine at 440Hz,  44100 stereo wav
      filename = "sine440Hz.wav"
      sweep_stereo = sweep_mono & sweep_mono
      gst_audio_encoder = "wavenc"
      sweep_mono = SineArray(
          duration=8, samplerate=samplerate, frequency=440
      )
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=sweep_stereo,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      # sine at 440Hz,  44100 stereo mp3
      filename = "sine440Hz.mp3"
      gst_audio_encoder = ["lamemp3enc"]
      sweep_mono = SineArray(
          duration=8, samplerate=samplerate, frequency=440
      )
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=sweep_stereo,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      # sine at 440Hz,  44100 stereo ogg
      filename = "sine440Hz.ogg"
      gst_audio_encoder = ["vorbisenc", "vorbisparse", "oggmux"]
      sweep_mono = SineArray(
          duration=8, samplerate=samplerate, frequency=440
      )
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=sweep_stereo,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      # --------- Equal tempered scale ---------
      filename = "C4_scale.wav"
      samplerate = 44100
      f_C4 = 261.63
      f_D4 = 293.66
      f_E4 = 329.63
      f_F4 = 349.23
      f_G4 = 392.00
      f_A4 = 440.00
      f_B4 = 493.88
      f_C5 = 523.25
      sineC4 = SineArray(
          duration=1, samplerate=samplerate, frequency=f_C4
      )
      sineD4 = SineArray(
          duration=1, samplerate=samplerate, frequency=f_D4
      )
      sineE4 = SineArray(
          duration=1, samplerate=samplerate, frequency=f_E4
      )
      sineF4 = SineArray(
          duration=1, samplerate=samplerate, frequency=f_F4
      )
      sineG4 = SineArray(
          duration=1, samplerate=samplerate, frequency=f_G4
      )
      sineA4 = SineArray(
          duration=1, samplerate=samplerate, frequency=f_A4
      )
      sineB4 = SineArray(
          duration=1, samplerate=samplerate, frequency=f_B4
      )
      sineC5 = SineArray(
          duration=1, samplerate=samplerate, frequency=f_C5
      )
  
      silence = SilenceArray(duration=0.2, samplerate=samplerate)
  
      scale = (
          sineC4
          + silence
          + sineD4
          + silence
          + sineE4
          + silence
          + sineF4
          + silence
          + sineG4
          + silence
          + sineA4
          + silence
          + sineB4
          + silence
          + sineC5
      )
  
      gst_audio_encoder = "wavenc"
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=scale,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      # --------- White noise ---------
      # white noise - 44100Hz mono
      filename = "white_noise_mono.wav"
      samplerate = 44100
      noise = WhiteNoiseArray(duration=8, samplerate=samplerate)
      gst_audio_encoder = "wavenc"
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=noise,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      # white noise - 44100Hz stereo
      filename = "white_noise.wav"
      samplerate = 44100
      noise = WhiteNoiseArray(duration=8, samplerate=samplerate)
      noise_stereo = noise & noise
      gst_audio_encoder = "wavenc"
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=noise_stereo,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      # white noise - 32000Hz stereo
      filename = "white_noise_32000.wav"
      samplerate = 32000
      noise = WhiteNoiseArray(duration=8, samplerate=samplerate)
      noise_stereo = noise & noise
      gst_audio_encoder = "wavenc"
      sample_file = generate_sample_file(
          filename,
          samples_dir,
          gst_audio_encoder,
          sample_array=noise_stereo,
          overwrite=overwrite,
      )
      samples.update({filename: sample_file})
  
      return samples
  
imports: from __future__ import division
  import gi
  from gi.repository import GLib, Gst
  import numpy
  import scipy.signal.waveforms
  import os.path
  import ffmpeg
label_desc: Use image node_id 2 for calling a global function with example usage: generateSamples(overwrite, samples_dir) and returns: samples