czyoung commited on
Commit
7ad02df
·
verified ·
1 Parent(s): 58c4533

Added simple versioning

Browse files
Files changed (1) hide show
  1. sonogram.py +27 -3
sonogram.py CHANGED
@@ -5,10 +5,13 @@ import torch
5
  import soundfile as sf
6
  import numpy as np
7
  from pyannote.core import Segment
 
 
 
8
 
9
  class Sonogram():
10
 
11
- def __init__(self):
12
  self.earlyCleanup = True
13
 
14
  self.isTPU = False
@@ -26,8 +29,29 @@ class Sonogram():
26
  print(f"GPU is not available")
27
  self.device = torch.device("cuda" if self.isGPU else "cpu")
28
  print(f"Using {self.device} instead.")
29
-
30
- self.pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  self.pipeline.to(self.device)
32
 
33
  # Load SVM classifier
 
5
  import soundfile as sf
6
  import numpy as np
7
  from pyannote.core import Segment
8
+ from pyannote.audio.models.segmentation import PyanNet
9
+ from pyannote.audio import Inference
10
+ from pyannote.pipeline.parameter import ParamDict
11
 
12
  class Sonogram():
13
 
14
+ def __init__(self,version='speaker-diarization-3.1'):
15
  self.earlyCleanup = True
16
 
17
  self.isTPU = False
 
29
  print(f"GPU is not available")
30
  self.device = torch.device("cuda" if self.isGPU else "cpu")
31
  print(f"Using {self.device} instead.")
32
+
33
+ self.version = version
34
+ if version == 'speaker-diarization-3.1':
35
+ self.pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1")
36
+ elif version == '1.0':
37
+ baselinePipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1")
38
+ newSpecs = baselinePipeline._segmentation.model.specifications
39
+ segModel = PyanNet.from_pretrained('20251208_Sonogram_Segmentation.ckpt')
40
+ segModel.specifications = newSpecs
41
+
42
+ segmentation_duration = segModel.specifications.duration
43
+ baselinePipeline._segmentation = Inference(
44
+ segModel,
45
+ duration=segmentation_duration,
46
+ step=baselinePipeline.segmentation_step * segmentation_duration,
47
+ skip_aggregation=True,
48
+ batch_size=1,
49
+ )
50
+
51
+ baselinePipeline.segmentation = ParamDict(min_duration_off=0.0,)
52
+ self.pipeline = baselinePipeline
53
+
54
+
55
  self.pipeline.to(self.device)
56
 
57
  # Load SVM classifier