def slice_comp():
  # similar slices from two audio clips should get a score of >0.7
  s1 = fft_freq_intensity(wave_to_list('tests/samples/jiehan-jiehan_s8.wav'))
  s2 = fft_freq_intensity(wave_to_list('tests/samples/jiehan-kane_s7.wav'))

  # plot_fft(*s1)
  # plot_fft(*s2)
  # plot_show()
  
  time_started = time()
  result = fft_similarity(s1[0], s1[1],
                          s2[0], s2[1])
  print "jiehan: jiehan8 -- kane7 =", result, "in", time() - time_started
  # assert result >= 0.7, "jiehan: jiehan8 -- kane7 score is too low (%f)" % result


  # similar slices from two audio clips should get a score of >0.7
  s1 = fft_freq_intensity(wave_to_list('tests/samples/jiehan-jiehan_s8.wav'))
  s2 = fft_freq_intensity(wave_to_list('tests/samples/jiehan-sean_s11.wav'))
  
  time_started = time()  
  result = fft_similarity(s1[0], s1[1],
                          s2[0], s2[1])
  print "jiehan: jiehan8 -- sean11 =", result, "in", time() - time_started
  # assert result >= 0.9, "jiehan: jiehan8 -- sean11 score is too low (%f)" % result

  # different slices from two audio clips should get a score of <0.4
  s1 = fft_freq_intensity(wave_to_list('tests/samples/jiehan-jiehan_s11.wav'))
  s2 = fft_freq_intensity(wave_to_list('tests/samples/kane-kane_s5.wav'))

  time_started = time()
  result = fft_similarity(s1[0], s1[1],
                          s2[0], s2[1])
  print "diff: jiehan8 -- kane4 =", result, "in", time() - time_started
Exemplo n.º 2
0
import wave
import re
import pyaudio
import struct
import math
from pylab import *
from utils.input import wave_to_list
from utils.data import slice_audio
from utils.fft import fft_freq_intensity

sample_slices = slice_audio(wave_to_list(sys.argv[1]), 2048)

if len(sys.argv) >= 3 and sys.argv[2] >= 0:
    slice = sample_slices[int(sys.argv[2])]

    freq, intensity = fft_freq_intensity(slice)

    title("audio %s" % sys.argv[2])
    xlim(70, 7000)
    ylim(0, 170)
    fill_between(freq, intensity)
    plot(freq, intensity, "r.")

    p = pyaudio.PyAudio()

    wf = wave.open(re.sub(r"\.", "_s" + sys.argv[2] + ".", sys.argv[1]), "wb")
    wf.setnchannels(1)
    wf.setsampwidth(p.get_sample_size(pyaudio.paInt16))
    wf.setframerate(44100)
    for byte in slice:
        wf.writeframes(struct.pack("h", byte))