diart icon indicating copy to clipboard operation
diart copied to clipboard

added method for a save wavform as wav format

Open m15kh opened this issue 1 year ago • 1 comments

Hi,

I noticed that your project doesn't have a way in to save waveforms as WAV format. I have written a method for this and added it to interface.py.

To use this method, simply include the following code:

inference.attach_hooks(inference.save_waveform_hook("output")) This code allows users to easily save any desired segment as a WAV file.

full example

from diart import SpeakerDiarization, VoiceActivityDetection, VoiceActivityDetectionConfig
from diart.sources import MicrophoneAudioSource, FileAudioSource, TorchStreamAudioSource
from diart.inference import StreamingInference
from diart.sinks import RTTMWriter
import diart.models as m
from diart import PipelineConfig



config = PipelineConfig
path_model  = 'epoch=99-step=2000.ckpt'
config = VoiceActivityDetectionConfig(segmentation=m.SegmentationModel.from_pyannote(path_model))
pipeline = VoiceActivityDetection(config=config)
mic = MicrophoneAudioSource()
inference = StreamingInference(pipeline, mic, do_plot=True, do_profile=True) 

inference.attach_hooks(inference.save_waveform_hook("out"))

total_prediction = inference()

m15kh avatar Nov 08 '24 18:11 m15kh

Hi @m15kh, thank you for opening this PR. Leaving out behavior for very specific use cases like this one was actually a planned decision for the design of the library. The hook mechanism is a way of allowing users to craft and inject custom code into a streaming pipeline exactly in the way that you did. However, unless the feature is heavily requested and there's a very good reason to include it in the library, I would prefer to leave specific hooks out.

juanmc2005 avatar Dec 13 '24 09:12 juanmc2005