FRE-5006: VoicePrint quality improvements
- P2-1: Consolidate mock ML logic to Python canonical source - P2-2: Fix weak hashes with SHA-256 - P2-3: Parallelize batch processing with Promise.allSettled() - P2-4: Add DI pattern support to services - P2-5: Add structured logging utility - P3-2: Persist batch jobId for result retrieval Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
voicePrintFeatureFlags,
|
||||
} from './voiceprint.config';
|
||||
import { checkFlag } from './voiceprint.feature-flags';
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
// Audio preprocessing service
|
||||
export class AudioPreprocessor {
|
||||
@@ -197,12 +198,10 @@ export class VoiceEnrollmentService {
|
||||
}
|
||||
|
||||
private computeEmbeddingHash(embedding: number[]): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < embedding.length; i++) {
|
||||
hash = ((hash << 5) - hash) + embedding[i];
|
||||
hash |= 0;
|
||||
}
|
||||
return `vp_${Math.abs(hash).toString(16)}_${embedding.length}`;
|
||||
const hash = createHash('sha256')
|
||||
.update(JSON.stringify(embedding))
|
||||
.digest('hex');
|
||||
return `vp_${hash.substring(0, 16)}_${embedding.length}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,13 +286,10 @@ export class AnalysisService {
|
||||
}
|
||||
|
||||
private computeAudioHash(buffer: Buffer): string {
|
||||
let hash = 0;
|
||||
const sampleSize = Math.min(buffer.length, 1024);
|
||||
for (let i = 0; i < sampleSize; i += 8) {
|
||||
hash = ((hash << 5) - hash) + buffer.readUInt8(i);
|
||||
hash |= 0;
|
||||
}
|
||||
return `audio_${Math.abs(hash).toString(16)}`;
|
||||
const hash = createHash('sha256')
|
||||
.update(buffer)
|
||||
.digest('hex');
|
||||
return `audio_${hash.substring(0, 16)}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user