superbrain-server 1.0.38 → 1.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/payload/analyzers/music_identifier.py +19 -17
- package/payload/main.py +7 -3
package/package.json
CHANGED
|
@@ -108,12 +108,13 @@ def _segment_positions(duration: float) -> list[float]:
|
|
|
108
108
|
|
|
109
109
|
async def _shazam_recognize_file(shazam, path: str) -> dict | None:
|
|
110
110
|
try:
|
|
111
|
-
# t2.micro
|
|
112
|
-
|
|
111
|
+
# t2.micro intances do heavy FFT math in python, which can take ~1.5 seconds per 1 second of audio.
|
|
112
|
+
# A 20s slice takes ~30-40s on standard micro instance caps.
|
|
113
|
+
result = await asyncio.wait_for(shazam.recognize(path), timeout=120.0)
|
|
113
114
|
if result and "track" in result:
|
|
114
115
|
return result
|
|
115
116
|
except asyncio.TimeoutError:
|
|
116
|
-
print("(shazam request timeout)")
|
|
117
|
+
print("(shazam request timeout 120s)")
|
|
117
118
|
except Exception as e:
|
|
118
119
|
print(f"(shazam error: {e})")
|
|
119
120
|
return None
|
|
@@ -140,21 +141,22 @@ async def _shazam_multi_segment(audio_path: str) -> dict | None:
|
|
|
140
141
|
label = f"@{int(start)}s" if start > 0 else "start"
|
|
141
142
|
print(f" [Shazam] {i}/{total} {label}...", end=" ", flush=True)
|
|
142
143
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
# NEVER pass the raw original file to Shazam on AWS t2.micro, because
|
|
145
|
+
# shazamio does a pure-Python FFT over the ENTIRE file length before sending!
|
|
146
|
+
# A 60 second file's FFT will easily hit a 60-second timeout on a micro vCPU.
|
|
147
|
+
# We MUST slice it to a tiny segment first using ffmpeg.
|
|
148
|
+
seg = _extract_segment(audio_path, start, duration=12)
|
|
149
|
+
if not seg:
|
|
150
|
+
print("(extract failed)")
|
|
151
|
+
continue
|
|
152
|
+
|
|
153
|
+
try:
|
|
154
|
+
result = await _shazam_recognize_file(shazam, seg)
|
|
155
|
+
finally:
|
|
151
156
|
try:
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
os.remove(seg)
|
|
156
|
-
except Exception:
|
|
157
|
-
pass
|
|
157
|
+
os.remove(seg)
|
|
158
|
+
except Exception:
|
|
159
|
+
pass
|
|
158
160
|
|
|
159
161
|
if result:
|
|
160
162
|
print("match!")
|
package/payload/main.py
CHANGED
|
@@ -83,9 +83,13 @@ def generate_final_summary(results, instagram_url):
|
|
|
83
83
|
music_info = "MUSIC:\n"
|
|
84
84
|
for item in results['music_identification']:
|
|
85
85
|
output = item['output']
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
# Accommodate potential emoji stripping in basic linux terminals
|
|
87
|
+
if 'Song:' in output:
|
|
88
|
+
song_line = [line for line in output.split('\n') if 'Song:' in line][0]
|
|
89
|
+
artist_line = [line for line in output.split('\n') if 'Artist:' in line]
|
|
90
|
+
|
|
91
|
+
song = song_line.split('Song:')[1].strip()
|
|
92
|
+
artist = artist_line[0].split('Artist:')[1].strip() if artist_line else 'Unknown'
|
|
89
93
|
music_info += f"- {song} by {artist}\n"
|
|
90
94
|
elif 'No match found' in output:
|
|
91
95
|
music_info += "- No music identified (likely voiceover/no background music)\n"
|