Необходимо изменить VAD режим с pyannote на другой, гораздо лучше
- User
Необходимо изменить VAD режим с pyannote на другой, гораздо лучше
- Assistant
Для замены Voice Activity Detection (VAD) модели с
pyannoteна другую, более подходящую для ваших нужд, необходимо выполнить следующие шаги:
1. Определить альтернативную VAD модель
Найдите более подходящую модель VAD, которая соответствует вашим требованиям. Вот несколько популярных вариантов:
- Silero VAD: Легковесная и точная VAD модель от Silero, доступная в Python (GitHub).
- Webrtcvad: Простая и эффективная библиотека для детектирования речи (GitHub).
- Google Cloud Speech-to-Text: Встроенная VAD поддержка в их сервисе.
2. Заменить вызов pyannote VAD
В текущем коде VAD используется через
pyannote.audio.Pipeline(см. файлvad_utils.py), где модель загружается черезPipeline.from_pretrained()и используется для сегментации аудио. Вам нужно заменить этот процесс на вызов вашей альтернативной модели.
3. Пример реализации Silero VAD
Если вы хотите использовать Silero VAD, вот пример того, как это можно интегрировать вместо
pyannote:Установите Silero VAD:
bashpip install silero-vadЗамените функцию
segment_audio:Перепишите метод
segment_audioвvad_utils.pyследующим образом:python - User
C:\Users\murdashev\PycharmProjects\gigaam.venv\Lib\site-packages\torch\hub.py:330: UserWarning: You are about to download and run code from an untrusted repository. In a future release, this won't be allowed. To add the repository to your trusted list, change the command to {calling_fn}(..., trust_repo=False) and a command prompt will appear asking for an explicit confirmation of trust, or load(..., trust_repo=True), which will assume that the prompt is to be answered with 'yes'. You can also use load(..., trust_repo='check') which will only prompt for confirmation if the repo is not already trusted. This will eventually be the default behaviour warnings.warn( Downloading: "https://github.com/snakers4/silero-vad/zipball/master" to C:\Users\murdashev/.cache\torch\hub\master.zip Traceback (most recent call last): File "C:\Users\murdashev\PycharmProjects\gigaam.venv\Lib\site-packages\torch\utils_contextlib.py", line 116, in decorate_context return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\murdashev\PycharmProjects\gigaam\GigaAM\gigaam\model.py", line 153, in transcribe_longform segments, boundaries = segment_audio( ^^^^^^^^^^^^^^ File "C:\Users\murdashev\PycharmProjects\gigaam\GigaAM\gigaam\vad_utils.py", line 61, in segment_audio speech_timestamps = get_speech_timestamps( ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\murdashev\PycharmProjects\gigaam.venv\Lib\site-packages\torch\utils_contextlib.py", line 116, in decorate_context return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\murdashev\PycharmProjects\gigaam.venv\Lib\site-packages\silero_vad\utils_vad.py", line 278, in get_speech_timestamps model.reset_states() ^^^^^^^^^^^^^^^^^^ AttributeError: 'tuple' object has no attribute 'reset_states' python-BaseException
- Assistant
- User
def segment_audio( wav_tensor: torch.Tensor, sample_rate: int, max_duration: float = 22.0, min_duration: float = 15.0, new_chunk_threshold: float = 0.2, ) -> Tuple[List[torch.Tensor], List[Tuple[float, float]]]: """ Segments an audio waveform into smaller chunks using Silero VAD. """ # Convert PyTorch tensor to NumPy array for Silero wav_array = wav_tensor.numpy()
code# Use Silero VAD to get timestamps of speech segments speech_timestamps = get_speech_timestamps( audio=wav_array, model=model, # Убедитесь, что это объект модели, а не кортеж sampling_rate=sample_rate ) segments: List[torch.Tensor] = [] boundaries: List[Tuple[float, float]] = [] for ts in speech_timestamps: start = ts['start'] / sample_rate end = ts['end'] / sample_rate # Ensure the segment duration is within the acceptable range if end - start > max_duration: end = start + max_duration if end - start < min_duration: continue # Extract the segment and append to the results start_sample = int(start * sample_rate) end_sample = int(end * sample_rate) segment = wav_tensor[start_sample:end_sample] segments.append(segment) boundaries.append((start, end)) return segments, boundaries - Assistant
- User
Теперь нормально. Но пустой transcript. Хотя голос есть: @torch.inference_mode() def transcribe_longform( self, wav_file: str, **kwargs ) -> List[Dict[str, Union[str, Tuple[float, float]]]]: """ Transcribes a long audio file by splitting it into segments and then transcribing each segment. """ from .vad_utils import segment_audio
codetranscribed_segments = [] wav = load_audio(wav_file, return_format="int") segments, boundaries = segment_audio( wav, SAMPLE_RATE, **kwargs ) for segment, segment_boundaries in zip(segments, boundaries): wav = segment.to(self._device).unsqueeze(0).to(self._dtype) length = torch.full([1], wav.shape[-1], device=self._device) encoded, encoded_len = self.forward(wav, length) result = self.decoding.decode(self.head, encoded, encoded_len)[0] transcribed_segments.append( { "transcription": result, "boundaries": segment_boundaries, } ) return transcribed_segments - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.