Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 575fbac099 | |||
| 46ae0f7913 |
@@ -75,6 +75,7 @@ A TypeScript library that provides a unified interface for working with multiple
|
|||||||
|
|
||||||
#### Instructions
|
#### Instructions
|
||||||
1. Install the package: `npm i @ztimson/ai-utils`
|
1. Install the package: `npm i @ztimson/ai-utils`
|
||||||
|
2. For speaker diarization: `pip install pyannote.audio`
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@@ -90,8 +91,9 @@ A TypeScript library that provides a unified interface for working with multiple
|
|||||||
|
|
||||||
#### Instructions
|
#### Instructions
|
||||||
1. Install the dependencies: `npm i`
|
1. Install the dependencies: `npm i`
|
||||||
2. Build library: `npm build`
|
2. For speaker diarization: `pip install pyannote.audio`
|
||||||
3. Run unit tests: `npm test`
|
3. Build library: `npm build`
|
||||||
|
4. Run unit tests: `npm test`
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "0.6.0",
|
"version": "0.6.2",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {spawn} from 'node:child_process';
|
import {spawn} from 'node:child_process';
|
||||||
import { pipeline } from '@xenova/transformers';
|
import {pipeline, read_audio} from '@xenova/transformers';
|
||||||
import {AbortablePromise, Ai} from './ai.ts';
|
import {AbortablePromise, Ai} from './ai.ts';
|
||||||
|
|
||||||
export class Audio {
|
export class Audio {
|
||||||
@@ -33,7 +33,7 @@ export class Audio {
|
|||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async isPyannoteInstalled(): Promise<boolean> {
|
async canDiarization(): Promise<boolean> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const proc = spawn('python3', ['-c', 'import pyannote.audio']);
|
const proc = spawn('python3', ['-c', 'import pyannote.audio']);
|
||||||
proc.on('close', (code: number) => resolve(code === 0));
|
proc.on('close', (code: number) => resolve(code === 0));
|
||||||
@@ -42,7 +42,7 @@ export class Audio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async runDiarization(audioPath: string): Promise<any[]> {
|
private async runDiarization(audioPath: string): Promise<any[]> {
|
||||||
if(!await this.isPyannoteInstalled()) throw new Error('Pyannote is not installed: pip install pyannote.audio');
|
if(!await this.canDiarization()) throw new Error('Pyannote is not installed: pip install pyannote.audio');
|
||||||
const script = `
|
const script = `
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
@@ -96,7 +96,8 @@ print(json.dumps(segments))
|
|||||||
|
|
||||||
// Transcript
|
// Transcript
|
||||||
if(aborted) return resolve(null);
|
if(aborted) return resolve(null);
|
||||||
const transcriptResult = await this.whisperPipeline(path, {return_timestamps: speaker ? 'word' : false, chunk_length_s: 30,});
|
const audio = await read_audio(path, 16000);
|
||||||
|
const transcriptResult = await this.whisperPipeline(audio, {return_timestamps: speaker ? 'word' : false, chunk_length_s: 30,});
|
||||||
if(!speaker) return resolve(transcriptResult.text?.trim() || null);
|
if(!speaker) return resolve(transcriptResult.text?.trim() || null);
|
||||||
|
|
||||||
// Speaker Diarization
|
// Speaker Diarization
|
||||||
|
|||||||
Reference in New Issue
Block a user