Skip to content

Commit

Permalink
Move decode and transform into transformers.js
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Feb 24, 2024
1 parent d75a9ad commit 9288744
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 75 deletions.
11 changes: 2 additions & 9 deletions components/models/ASR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ export function Interact({ settings: { model }, params, runPipe }: InteractProps
const call = useCallback(async (audio) => {
setWIP(true);
try {
logger.time('TRANSFORM');
audio = downsample(toSingleChannel(audio), 16000);
logger.timeEnd('TRANSFORM');
const { text } = await runPipe('automatic-speech-recognition', model, null, audio.data, params);
const { text } = await runPipe('automatic-speech-recognition', model, null, audio, params);
setOutput(text);
} catch {}
setWIP(false);
Expand Down Expand Up @@ -83,11 +80,7 @@ export function Interact({ settings: { model }, params, runPipe }: InteractProps

const runExample = useCallback(async () => {
if (!example) return;
const buf = await getFile(example);
logger.time('DECODE');
const audio = await decodeBuffer(buf);
logger.timeEnd('DECODE');
call(audio);
call(await getFile(example));
}, [call, example]);

const playExample = useCallback(async () => {
Expand Down
6 changes: 3 additions & 3 deletions utils/fs-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import RNFS from 'react-native-fs';
import { Buffer } from 'buffer';
import sha from 'sha.js';

export const getFile = async (url: string): Buffer => {
export const getFile = async (url: string): string => {
const filename = sha('sha256').update(url).digest('hex');
const path = `${RNFS.CachesDirectoryPath}/${filename}`;
const path = `${RNFS.CachesDirectoryPath}/${filename}.wav`;

if (!await RNFS.exists(path)) {
await RNFS.downloadFile({
Expand All @@ -13,5 +13,5 @@ export const getFile = async (url: string): Buffer => {
}).promise;
}

return Buffer.from(await RNFS.readFile(path, 'base64'), 'base64');
return path;
}
66 changes: 3 additions & 63 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1277,11 +1277,6 @@
dependencies:
"@hapi/hoek" "^9.0.0"

"@huggingface/jinja@^0.1.0":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@huggingface/jinja/-/jinja-0.1.2.tgz#073fa0a68ef481a1806b0186bbafd8013e586fbe"
integrity sha512-x5mpbfJt1nKmVep5WNP5VjNsjWApWNj8pPYI+uYMkBWH9bWUJmQmHt2lbf0VCoQd54Oq3XuFEh/UyoVh7rPxmg==

"@huggingface/jinja@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@huggingface/jinja/-/jinja-0.1.3.tgz#202cc080bcca92cb7c89e179a084a598cbfe35e0"
Expand Down Expand Up @@ -1998,11 +1993,6 @@
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz"
integrity sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==

"@types/long@^4.0.1":
version "4.0.2"
resolved "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz"
integrity sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==

"@types/node@*", "@types/node@>=13.7.0":
version "20.6.0"
resolved "https://registry.npmjs.org/@types/node/-/node-20.6.0.tgz"
Expand Down Expand Up @@ -2161,7 +2151,7 @@

"@xenova/transformers@https://github.com/hans00/transformers.js.git#merge":
version "2.15.1"
resolved "https://github.com/hans00/transformers.js.git#c0dda59e0ff7fe9e9864dc4470cc941423a4d9d0"
resolved "https://github.com/hans00/transformers.js.git#8cd25a45388c56a38e548950151e4f018ca59576"
dependencies:
"@huggingface/jinja" "^0.1.3"
image-decode "^1.2.2"
Expand Down Expand Up @@ -5597,11 +5587,6 @@ logkitty@^0.7.1:
dayjs "^1.8.15"
yargs "^15.1.0"

long@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/long/-/long-4.0.0.tgz"
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==

long@^5.0.0, long@^5.2.3:
version "5.2.3"
resolved "https://registry.yarnpkg.com/long/-/long-5.2.3.tgz#a3ba97f3877cf1d778eccbcb048525ebb77499e1"
Expand Down Expand Up @@ -6440,33 +6425,19 @@ onetime@^5.1.0, onetime@^5.1.2:
dependencies:
mimic-fn "^2.1.0"

onnx-proto@^4.0.4:
version "4.0.4"
resolved "https://registry.npmjs.org/onnx-proto/-/onnx-proto-4.0.4.tgz"
integrity sha512-aldMOB3HRoo6q/phyB6QRQxSt895HNNw82BNyZ2CMh4bjeKv7g/c+VpAFtJuEMVfYLMbRx61hbuqnKceLeDcDA==
dependencies:
protobufjs "^6.8.8"

[email protected], onnxruntime-common@~1.14.0:
[email protected]:
version "1.17.0"
resolved "https://registry.yarnpkg.com/onnxruntime-common/-/onnxruntime-common-1.17.0.tgz#b2534ce021b1c1b19182bec39aaea8d547d2013e"
integrity sha512-Vq1remJbCPITjDMJ04DA7AklUTnbYUp4vbnm6iL7ukSt+7VErH0NGYfekRSTjxxurEtX7w41PFfnQlE6msjPJw==

[email protected]:
version "1.14.0"
resolved "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.14.0.tgz"
integrity sha512-5ba7TWomIV/9b6NH/1x/8QEeowsb+jBEvFzU6z0T4mNsFwdPqXeFUM7uxC6QeSRkEbWu3qEB0VMjrvzN/0S9+w==
dependencies:
onnxruntime-common "~1.14.0"

onnxruntime-node@^1.17.0:
version "1.17.0"
resolved "https://registry.yarnpkg.com/onnxruntime-node/-/onnxruntime-node-1.17.0.tgz#38af0ba527cb44c1afb639bdcb4e549edba029a1"
integrity sha512-pRxdqSP3a6wtiFVkVX1V3/gsEMwBRUA9D2oYmcN3cjF+j+ILS+SIY2L7KxdWapsG6z64i5rUn8ijFZdIvbojBg==
dependencies:
onnxruntime-common "1.17.0"

onnxruntime-react-native@1.14.0, onnxruntime-react-native@1.17.0, onnxruntime-react-native@^1.17.0:
[email protected], onnxruntime-react-native@^1.17.0:
version "1.17.0"
resolved "https://registry.yarnpkg.com/onnxruntime-react-native/-/onnxruntime-react-native-1.17.0.tgz#565df926eaea55605a0dfe12821e46ee481b040d"
integrity sha512-leakzleuCL6P69j10pPemZhFc7avo2kLO5b12HPiGHGKepZVzXTq7Ss1x1CS5ZjOIxMj9q0s5O9yYAUp++vBpg==
Expand All @@ -6475,18 +6446,6 @@ [email protected], [email protected], onnxruntime-re
buffer "^6.0.3"
onnxruntime-common "1.17.0"

[email protected]:
version "1.14.0"
resolved "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.14.0.tgz"
integrity sha512-Kcqf43UMfW8mCydVGcX9OMXI2VN17c0p6XvR7IPSZzBf/6lteBzXHvcEVWDPmCKuGombl997HgLqj91F11DzXw==
dependencies:
flatbuffers "^1.12.0"
guid-typescript "^1.0.9"
long "^4.0.0"
onnx-proto "^4.0.4"
onnxruntime-common "~1.14.0"
platform "^1.3.6"

onnxruntime-web@^1.17.0:
version "1.17.0"
resolved "https://registry.yarnpkg.com/onnxruntime-web/-/onnxruntime-web-1.17.0.tgz#cff8e383a1ed4e72bd735350530a3666d9efb4aa"
Expand Down Expand Up @@ -6839,25 +6798,6 @@ prop-types@*, prop-types@^15.8.1:
object-assign "^4.1.1"
react-is "^16.13.1"

protobufjs@^6.8.8:
version "6.11.4"
resolved "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.4.tgz"
integrity sha512-5kQWPaJHi1WoCpjTGszzQ32PG2F4+wRY6BmAT4Vfw56Q2FZ4YZzK20xUYQH4YkfehY1e6QSICrJquM6xXZNcrw==
dependencies:
"@protobufjs/aspromise" "^1.1.2"
"@protobufjs/base64" "^1.1.2"
"@protobufjs/codegen" "^2.0.4"
"@protobufjs/eventemitter" "^1.1.0"
"@protobufjs/fetch" "^1.1.0"
"@protobufjs/float" "^1.0.2"
"@protobufjs/inquire" "^1.1.0"
"@protobufjs/path" "^1.1.2"
"@protobufjs/pool" "^1.1.0"
"@protobufjs/utf8" "^1.1.0"
"@types/long" "^4.0.1"
"@types/node" ">=13.7.0"
long "^4.0.0"

protobufjs@^7.2.4:
version "7.2.6"
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-7.2.6.tgz#4a0ccd79eb292717aacf07530a07e0ed20278215"
Expand Down

0 comments on commit 9288744

Please sign in to comment.