-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* UI Improvements * cleanup EUI * more style * revert * remove css * remove outline * cleanup screen * Select * list adjustments * disabled states * disabled and numbers style * context fix and login * webhooks red trashcan * session * changes ui * wip * whisp * wip * wip * wip * almost * icons * pre * pre-release * remove unused * remove comment block * remove console
- Loading branch information
1 parent
afbd0bd
commit 4b96958
Showing
32 changed files
with
1,103 additions
and
1,123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,7 @@ yarn-error.* | |
# @end @expo/electron-adapter | ||
|
||
/web/config*.json | ||
/web/*.webm | ||
/web/*.wav | ||
/web/*.ogg | ||
/web/*.mp3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,67 @@ | ||
import { request } from './utils'; | ||
import * as whisper from 'whisper-webgpu'; | ||
import toWav from 'audiobuffer-to-wav'; | ||
|
||
export const tts = async ({ audio: body }) => { | ||
const port = 13003; | ||
const endpoint = `http://localhost:${port}/transcribe`; | ||
const transcript = await request({ endpoint, body }); | ||
const CACHE = {}; | ||
const S3Q = 'https://kunziteq.s3.gra.perf.cloud.ovh.net'; | ||
|
||
return transcript; | ||
export const wavBytes = async ({ chunks }) => { | ||
// TODO: flatten 2 channels | ||
let arrayBuffer = await chunks[0].arrayBuffer(); | ||
const audioContext = new AudioContext(); | ||
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer); | ||
const wavBlob = new Blob([toWav(audioBuffer)], { type: 'audio/wav' }); | ||
|
||
arrayBuffer = await wavBlob.arrayBuffer(); | ||
|
||
return new Uint8Array(arrayBuffer); | ||
}; | ||
|
||
export const ttsInfer = async ({ | ||
chunks, | ||
url, | ||
audio = [], | ||
bin = `${S3Q}/ttsb.bin`, | ||
data = `${S3Q}/tts.json` | ||
}) => { | ||
const fetchBytes = async url => { | ||
if (!CACHE[url]) { | ||
const response = await fetch(url); | ||
const buffer = await response.arrayBuffer(); | ||
const bytes = new Uint8Array(buffer); | ||
|
||
CACHE[url] = bytes; | ||
} | ||
|
||
return CACHE[url]; | ||
}; | ||
|
||
const tokenizer = await fetchBytes(data); | ||
const model = await fetchBytes(bin); | ||
|
||
if (url) audio = await fetchBytes(url); | ||
if (chunks) audio = await wavBytes({ chunks }); | ||
|
||
await whisper.default(); | ||
const builder = new whisper.SessionBuilder(); | ||
const session = await builder.setModel(model).setTokenizer(tokenizer).build(); | ||
|
||
const { segments } = await session.run(audio); | ||
|
||
session.free(); | ||
|
||
return segments; | ||
}; | ||
|
||
export const tts = async ({ audio }) => { | ||
const remote = (await ttsInfer({ audio: audio.remote })).map(item => ({ | ||
...item, | ||
channel: 'remote' | ||
})); | ||
const local = (await ttsInfer({ audio: audio.local })).map(item => ({ | ||
...item, | ||
channel: 'local' | ||
})); | ||
const merged = [...remote, ...local].sort((a, b) => a.start - b.start); | ||
|
||
return merged; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { tts } from './008Q'; | ||
|
||
let BUSY = false; | ||
const QUEUE = []; | ||
|
||
const process = async () => { | ||
console.log('[008Q] Processing...'); | ||
if (BUSY || !QUEUE.length) return; | ||
|
||
try { | ||
BUSY = true; | ||
|
||
const [data] = QUEUE; | ||
const { id, audio } = data; | ||
|
||
console.log('[008Q] Transcribing...'); | ||
const transcript = await tts({ audio }); | ||
|
||
self.postMessage({ id, transcript }); | ||
} catch (err) { | ||
console.error(err); | ||
} finally { | ||
QUEUE.shift(); | ||
BUSY = false; | ||
process(); | ||
} | ||
}; | ||
|
||
self.addEventListener('message', async ({ data }) => { | ||
console.log(`[008Q] Queuing job ${data.id}`); | ||
QUEUE.push(data); | ||
process(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.