ziqiangao commited on
Commit
f5213d4
·
1 Parent(s): 1d44699

update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -5
app.py CHANGED
@@ -15,9 +15,36 @@ import subprocess
15
  import traceback
16
  import time
17
  import shutil
 
18
 
19
  path = "" # Update with your path
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def getRenderCords(ta: list, idx: int, res: int = 1024, size: tuple = (1280, 720)) -> list:
22
  i = idx - res // 2
23
  x, y = size[0] * .9 / -2, (ta[i] - 128) * (size[1] / 2000) + (size[1] * .7 / -2)
@@ -38,11 +65,6 @@ def center_to_top_left(coords, width=1280, height=720):
38
  def totopleft(coord, width=1280, height=720):
39
  return coord[0] + width / 2, height / 2 - coord[1]
40
 
41
- def getTrigger(ad: int, a: list, max: int = 1024) -> int:
42
- i = ad
43
- while not (a[i] < 128 and not a[i + 2] < 128 or i - ad > max):
44
- i += 1
45
- return i
46
 
47
  def extract_cover_image(mp3_file):
48
  audio = MP3(mp3_file, ID3=ID3)
 
15
  import traceback
16
  import time
17
  import shutil
18
+ import numpy as np
19
 
20
  path = "" # Update with your path
21
 
22
+ # Cross-correlation function
23
+ def cross_correlation(x, y):
24
+ """
25
+ Compute the cross-correlation of two signals.
26
+ """
27
+ n = len(x)
28
+ correlation = np.correlate(x - np.mean(x), y - np.mean(y), mode='valid') / (n * np.std(x) * np.std(y))
29
+ return correlation
30
+
31
+ # Modified getTrigger function using cross-correlation
32
+ def getTrigger(ad, a, ref_length=100, max=1024):
33
+ """
34
+ Find the trigger point in the audio signal using waveform correlation.
35
+ """
36
+ ref_signal = a[ad:ad + ref_length] # Reference signal segment
37
+
38
+ max_corr = 0
39
+ best_idx = ad
40
+ for i in range(ad, len(a) - ref_length):
41
+ corr = cross_correlation(ref_signal, a[i:i + ref_length])
42
+ if corr > max_corr:
43
+ max_corr = corr
44
+ best_idx = i
45
+
46
+ return best_idx
47
+
48
  def getRenderCords(ta: list, idx: int, res: int = 1024, size: tuple = (1280, 720)) -> list:
49
  i = idx - res // 2
50
  x, y = size[0] * .9 / -2, (ta[i] - 128) * (size[1] / 2000) + (size[1] * .7 / -2)
 
65
  def totopleft(coord, width=1280, height=720):
66
  return coord[0] + width / 2, height / 2 - coord[1]
67
 
 
 
 
 
 
68
 
69
  def extract_cover_image(mp3_file):
70
  audio = MP3(mp3_file, ID3=ID3)