ziqiangao commited on
Commit
db725c9
·
1 Parent(s): d5c5640

revert app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -27
app.py CHANGED
@@ -15,36 +15,9 @@ import subprocess
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, ad+ref_length+max):
41
- #print(f"{i}, \t{ad},\t {len(a) - ref_length}")
42
- corr = cross_correlation(ref_signal, a[i:i + ref_length])
43
- if corr > max_corr:
44
- max_corr = corr
45
- best_idx = i
46
-
47
- return best_idx
48
 
49
  def getRenderCords(ta: list, idx: int, res: int = 1024, size: tuple = (1280, 720)) -> list:
50
  i = idx - res // 2
@@ -66,6 +39,11 @@ def center_to_top_left(coords, width=1280, height=720):
66
  def totopleft(coord, width=1280, height=720):
67
  return coord[0] + width / 2, height / 2 - coord[1]
68
 
 
 
 
 
 
69
 
70
  def extract_cover_image(mp3_file):
71
  audio = MP3(mp3_file, ID3=ID3)
 
15
  import traceback
16
  import time
17
  import shutil
 
18
 
19
  path = "" # Update with your path
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def getRenderCords(ta: list, idx: int, res: int = 1024, size: tuple = (1280, 720)) -> list:
23
  i = idx - res // 2
 
39
  def totopleft(coord, width=1280, height=720):
40
  return coord[0] + width / 2, height / 2 - coord[1]
41
 
42
+ def getTrigger(ad: int, a: list, max: int = 1024) -> int:
43
+ i = ad
44
+ while not (a[i] < 128 and not a[i + 2] < 128 or i - ad > max):
45
+ i += 1
46
+ return i
47
 
48
  def extract_cover_image(mp3_file):
49
  audio = MP3(mp3_file, ID3=ID3)