Downloads · 30 days
4
8% of all-time downloads
Songhun/wav2vec2-base-960h-contrastive
wav2vec2-base-960h-contrastive is a feature extraction model from Songhun. Use it when you need embeddings to search or compare text. It is set up for transformers. The card lists the license as mit.
이 저장소는 음성 데이터를 기반으로 화자 인식 모델을 학습하고 사용하는 방법을 제공합니다. 한국어 음성 데이터셋인 AIHub의 화자 인식용 음성 데이터셋을 사용하여 학습이 진행된 모델입니다.
Downloads · 30 days
4
8% of all-time downloads
All-time downloads
49
Public
Repo size
755 MB
Likes
1
Public
Click a slice to open those files.
.bin378 MB · 100%
From the Hugging Face model README
이 저장소는 음성 데이터를 기반으로 화자 인식 모델을 학습하고 사용하는 방법을 제공합니다. 한국어 음성 데이터셋인 AIHub의 화자 인식용 음성 데이터셋을 사용하여 학습이 진행된 모델입니다.
The original model can be found facebook/wav2vec2-base-960h
import librosa
import torch
import torch.nn.functional as F
from transformers import Wav2Vec2Model
from transformers import Wav2Vec2FeatureExtractor
from torch.nn.functional import cosine_similarity
from transformers import Wav2Vec2Model, AutoFeatureExtractor
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model_name = "Songhun/wav2vec2-base-960h-contrastive"
model = Wav2Vec2Model.from_pretrained(model_name).to(device)
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
file_path1 = './test1.wav'
file_path2 = './test2.wav'
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(model_name)
def load_and_process_audio(file_path, feature_extractor, max_length=4.0):
audio, sampling_rate = librosa.load(file_path, sr=16000)
inputs = feature_extractor(audio, sampling_rate=sampling_rate, return_tensors="pt", padding="max_length", truncation=True, max_length=int(max_length * sampling_rate))
return inputs.input_values
audio_input1 = load_and_process_audio(file_path1, feature_extractor).to(device)
audio_input2 = load_and_process_audio(file_path2, feature_extractor).to(device)
embedding1 = model(audio_input1).last_hidden_state.mean(dim=1)
embedding2 = model(audio_input2).last_hidden_state.mean(dim=1)
similarity = F.cosine_similarity(embedding1, embedding2).item()
print(f"Similarity between the two audio files: {similarity}")
Threshold: 0.3331 is Youden's J statistic optimal threshold