vidsum-local 0.4.0__py3-none-any.whl
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.
- vidsum/__init__.py +2 -0
- vidsum/audio.py +52 -0
- vidsum/cli.py +892 -0
- vidsum/cloud.py +189 -0
- vidsum/fetch.py +601 -0
- vidsum/i18n.py +273 -0
- vidsum/mcp_server.py +189 -0
- vidsum/models.py +125 -0
- vidsum/review.py +137 -0
- vidsum/visual.py +211 -0
- vidsum_local-0.4.0.dist-info/METADATA +339 -0
- vidsum_local-0.4.0.dist-info/RECORD +16 -0
- vidsum_local-0.4.0.dist-info/WHEEL +5 -0
- vidsum_local-0.4.0.dist-info/entry_points.txt +4 -0
- vidsum_local-0.4.0.dist-info/licenses/LICENSE +21 -0
- vidsum_local-0.4.0.dist-info/top_level.txt +1 -0
vidsum/__init__.py
ADDED
vidsum/audio.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Offline Apple system sound classification (macOS only); no additional model weights."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
try:
|
|
4
|
+
import SoundAnalysis as S
|
|
5
|
+
from Foundation import NSObject, NSURL
|
|
6
|
+
from objc import super, protocolNamed
|
|
7
|
+
except ImportError: # not macOS: classify() raises, status() still works
|
|
8
|
+
S = None
|
|
9
|
+
|
|
10
|
+
if S is not None:
|
|
11
|
+
class VidsumSoundObserver(NSObject, protocols=[protocolNamed('SNResultsObserving')]):
|
|
12
|
+
def init(self):
|
|
13
|
+
self=super().init();self.rows=[];self.errors=[];return self
|
|
14
|
+
def request_didProduceResult_(self,request,result):
|
|
15
|
+
# Exceptions must not escape an Objective-C callback (that aborts Python).
|
|
16
|
+
try:
|
|
17
|
+
cs={str(c.identifier()):float(c.confidence()) for c in result.classifications()}
|
|
18
|
+
self.rows.append({'window_index':len(self.rows),
|
|
19
|
+
**{key:cs.get(key,0) for key in ['speech','music','singing','rapping']}})
|
|
20
|
+
except Exception as error:self.errors.append(str(error))
|
|
21
|
+
def request_didFailWithError_(self,request,error):self.errors.append(str(error))
|
|
22
|
+
def requestDidComplete_(self,request):pass
|
|
23
|
+
|
|
24
|
+
def classify(wav: Path):
|
|
25
|
+
if S is None:raise RuntimeError('SoundAnalysis is only available on macOS')
|
|
26
|
+
analyzer,error=S.SNAudioFileAnalyzer.alloc().initWithURL_error_(NSURL.fileURLWithPath_(str(wav.resolve())),None)
|
|
27
|
+
if not analyzer:raise RuntimeError(str(error))
|
|
28
|
+
request,error=S.SNClassifySoundRequest.alloc().initWithClassifierIdentifier_error_(S.SNClassifierIdentifierVersion1,None)
|
|
29
|
+
if not request:raise RuntimeError(str(error))
|
|
30
|
+
observer=VidsumSoundObserver.alloc().init()
|
|
31
|
+
ok,error=analyzer.addRequest_withObserver_error_(request,observer,None)
|
|
32
|
+
if not ok:raise RuntimeError(str(error))
|
|
33
|
+
analyzer.analyze()
|
|
34
|
+
if observer.errors:raise RuntimeError('; '.join(observer.errors))
|
|
35
|
+
rows=observer.rows
|
|
36
|
+
if not rows:raise RuntimeError('SoundAnalysis returned no windows')
|
|
37
|
+
stats={k:{'mean':sum(r[k] for r in rows)/len(rows),'max':max(r[k] for r in rows)} for k in ['speech','music','singing','rapping']}
|
|
38
|
+
return {'method':'Apple SoundAnalysis builtin version1; probabilistic, not proof of silence','statistics':stats,'windows':rows}
|
|
39
|
+
|
|
40
|
+
def status(segments,events,no_audio=False):
|
|
41
|
+
"""Return (code, segments). Codes are translated by i18n.T(lang,'audio')[code]."""
|
|
42
|
+
if no_audio:return 'no_audio',[]
|
|
43
|
+
stats=(events or {}).get('statistics',{})
|
|
44
|
+
if stats:
|
|
45
|
+
speech,music,singing,rapping=[stats[k] for k in ['speech','music','singing','rapping']]
|
|
46
|
+
if speech['max']<.12 and music['mean']>.35 and max(singing['max'],rapping['max'])<.2:
|
|
47
|
+
return 'music_only',[]
|
|
48
|
+
if max(singing['mean'],rapping['mean'])>.4 and speech['mean']<.65:
|
|
49
|
+
return 'singing',[]
|
|
50
|
+
if not segments:return 'no_speech',segments
|
|
51
|
+
suspicious=[s for s in segments if any(x in s['text'] for x in ['字幕志愿者','字幕由','Amara.org','谢谢观看','感謝觀看','Thanks for watching','Subtitles by'])]
|
|
52
|
+
return ('hallucination' if len(suspicious)==len(segments) else 'speech'),segments
|