diff --git a/python/audio2text/README.md b/python/audio2text/README.md index a960b48..dddc8d9 100644 --- a/python/audio2text/README.md +++ b/python/audio2text/README.md @@ -2,6 +2,8 @@ This Sequence transcribes an audio file to a text using AssemblyAI API. The example audio file is provided with this sample, replacing this audio file with another is possible but the file must be renamed to `song.wav`.
+The audio file +`song.wav` is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. ___ @@ -27,13 +29,13 @@ mkdir __pypackages__ pip3 install -t __pypackages__ -r requirements.txt # Pack the Sequence into a gzip format -si seq pack audio2text_py +si seq pack audio2text # Send the Sequence to the Transform-Hub, with a return value -si seq send audio2text_py.tar.gz +si seq send audio2text.tar.gz # Start a Sequence, with the AssemblyAi-key as an argument parameter -si seq start --args [\"\"] +si seq start --args [\"\"] # Transcription of the audio file as text output si inst output diff --git a/typescript/audio2text-event/README.md b/typescript/audio2text-event/README.md new file mode 100644 index 0000000..9ed7722 --- /dev/null +++ b/typescript/audio2text-event/README.md @@ -0,0 +1,60 @@ +# Audio2text Events + +This is best version of Audio2Text which uses input channel aswell as Events and allows sending more then 1 file + +The audio file +`song.wav` is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. + +___ + +## Description + +This is a sequence which transript audio file using AssemblyAi API. + +## Prerequisites + +> ❗ Remember to [setup transform-hub locally](https://docs.scramjet.org/platform/self-hosted-installation) or use the [platform's environment](https://docs.scramjet.org/platform/quick-start) for the sequence deployment. + +As this apps is using AssemblyAi Api, the key is required to use it. For informations how to get one please refer to [assemblyAi](https://www.assemblyai.com/) + +## Running + +Open the terminal and run the following commands: + +```bash +# go to 'repo-checker' directory +cd typescript/audio2text-event + +# install dependencies +npm install + +# transpile TS->JS to dist/ +npm run build + +# deploy the Sequence withh a following arguments where first one is a time interval in ms which determines how often to check for data and second is github api key +si seq deploy dist --args '["YOUR-GITHUB-API-KEY-HERE"]' + +# upload file to a instance +si inst input - /path/to/your/file -t application/octet-stream + +``` + +## Getting results + +All the informations generated by this instance will be available at the log channel. + +To get result simply type in console: + +`si inst output - ` + +## Using events + +To use events use commands `si inst event emit pause` to pause input stream and `si inst event emit pause` to resume it + +## Testing + +to make testing easier the sequence contains file ready to be uploaded. + +Logs when running this sequence with a sample file should look like this: + +![screenshot](https://github.com/scramjetorg/platform-samples/assets/53794300/1184b241-b11f-4b5a-b169-94b21ffcd44a) diff --git a/typescript/audio2text-event/package.json b/typescript/audio2text-event/package.json new file mode 100644 index 0000000..5fef446 --- /dev/null +++ b/typescript/audio2text-event/package.json @@ -0,0 +1,33 @@ +{ + "name": "text2audio-events", + "version": "1.0.0", + "description": "Sequence that uses AssemblyAi to transcript Audio sent by input channel", + "main": "audio2text-event/src/index.js", + "scripts": { + "prebuild": "cd ../audio2text && npm install", + "build": "tsc -p tsconfig.json", + "postbuild": "cp -r package.json dist/ && (cd dist && npm i --omit=dev)" + }, + "keywords": [ + "Ai", + "Stream", + "AssemblyAi" + ], + "repository": { + "type": "git", + "url": "https://github.com/scramjetorg/platform-samples/tree/main/typescript/audio2text-event" + }, + "author": "Piotr", + "license": "ISC", + "dependencies": { + "@scramjet/obj-logger": "^0.34.3", + "@scramjet/utility": "^0.34.3", + "axios": "^1.3.6", + "date-and-time": "^2.4.3" + }, + "devDependencies": { + "@scramjet/types": "0.34.3", + "@types/node": "^20.2.5", + "typescript": "^5.1.6" + } +} diff --git a/typescript/audio2text-event/song.wav b/typescript/audio2text-event/song.wav new file mode 100644 index 0000000..616f821 Binary files /dev/null and b/typescript/audio2text-event/song.wav differ diff --git a/typescript/audio2text-event/src/index.ts b/typescript/audio2text-event/src/index.ts new file mode 100644 index 0000000..9cc0ae5 --- /dev/null +++ b/typescript/audio2text-event/src/index.ts @@ -0,0 +1,45 @@ +import { ReadableApp } from "@scramjet/types"; +import { Assembly } from "../../audio2text/src/utils/assembly"; +import { PassThrough } from "stream"; + +const app: ReadableApp = async function(input, apiKey: string) { + const assembly = new Assembly(apiKey); + const output = new PassThrough({ defaultEncoding:"utf-8" }); + + assembly.logger.outputLogStream.pipe(this.logger.inputLogStream); + + let timer; + let helpStream: PassThrough = new PassThrough(); + + async function transcript() { + helpStream.end(); + await assembly.processFile(helpStream).then(res => { + this.logger.info("Result", res); + helpStream = new PassThrough(); + output.push(res); + }); + } + function startTimer() { + timer = setTimeout(() => { + transcript(); + }, 2000); + } + + input.on("data", (chunk) => { + if(!timer) { + startTimer(); + } + helpStream.push(chunk); + clearTimeout(timer); + startTimer(); + }); + this.on("pause", () => { + input.pause(); + }); + this.on("resume", () => { + input.resume(); + }); + return output; +}; + +export default app; diff --git a/typescript/audio2text-event/tsconfig.json b/typescript/audio2text-event/tsconfig.json new file mode 100644 index 0000000..4f0fb38 --- /dev/null +++ b/typescript/audio2text-event/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "lib": [ "ESNext" ], + "target": "ESNext", + "module": "CommonJS", + "outDir": "./dist", + "esModuleInterop": true, + "skipLibCheck": true, + "resolveJsonModule": true, + } +} diff --git a/typescript/audio2text-input/README.md b/typescript/audio2text-input/README.md new file mode 100644 index 0000000..9c2ac21 --- /dev/null +++ b/typescript/audio2text-input/README.md @@ -0,0 +1,62 @@ +# Audio2text Input + +This is another version which uses input channel instead of filesystem + +The audio file +`song.wav` is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. + +___ + +## Description + +This is a sequence which transript audio file using AssemblyAi API. + +## Prerequisites + +> ❗ Remember to [setup transform-hub locally](https://docs.scramjet.org/platform/self-hosted-installation) or use the [platform's environment](https://docs.scramjet.org/platform/quick-start) for the sequence deployment. + +As this apps is using AssemblyAi Api, the key is required to use it. For informations how to get one please refer to [assemblyAi](https://www.assemblyai.com/) + +## Running + +Open the terminal and run the following commands: + +```bash +# go to 'repo-checker' directory +cd typescript/audio2text-input + +# install dependencies +npm install + +# transpile TS->JS to dist/ +npm run build + +# Pack the Sequence into a gzip format +si seq pack dist + +# Send the Sequence to the Transform-Hub, with a return value +si seq send dist.tar.gz + +# Start a Sequence, with the AssemblyAi-key as an argument parameter +si seq start --args [\"\"] + +# upload file to a instance +si inst input - /path/to/your/file -e -t application/octet-stream + +``` + +## Getting results + +All the informations generated by this instance will be available at the log channel. + +To get result simply type in console: + +`si inst output - ` + +## Testing + +to make testing easier the sequence contains file ready to be uploaded. + +Logs when running this sequence with a sample file should look like this: + +![screenshot](https://github.com/scramjetorg/platform-samples/assets/53794300/1184b241-b11f-4b5a-b169-94b21ffcd44a) diff --git a/typescript/audio2text-input/package.json b/typescript/audio2text-input/package.json new file mode 100644 index 0000000..59f6809 --- /dev/null +++ b/typescript/audio2text-input/package.json @@ -0,0 +1,33 @@ +{ + "name": "audio2text-input", + "version": "1.0.0", + "description": "Sequence that uses AssemblyAi to transcript Audio sent by input channel", + "main": "audio2text-input/src/index.js", + "scripts": { + "prebuild": "cd ../audio2text && npm install", + "build": "tsc -p tsconfig.json", + "postbuild": "cp -r package.json dist/ && (cd dist && npm i --omit=dev)" + }, + "keywords": [ + "Ai", + "Stream", + "AssemblyAi" + ], + "repository": { + "type": "git", + "url": "https://github.com/scramjetorg/platform-samples/tree/main/typescript/audio2text" + }, + "author": "Piotr", + "license": "ISC", + "dependencies": { + "@scramjet/obj-logger": "^0.34.3", + "@scramjet/utility": "^0.34.3", + "axios": "^1.3.6", + "date-and-time": "^2.4.3" + }, + "devDependencies": { + "@scramjet/types": "0.33.5", + "@types/node": "^20.2.5", + "typescript": "^5.1.6" + } +} diff --git a/typescript/audio2text-input/song.wav b/typescript/audio2text-input/song.wav new file mode 100644 index 0000000..616f821 Binary files /dev/null and b/typescript/audio2text-input/song.wav differ diff --git a/typescript/audio2text-input/src/index.ts b/typescript/audio2text-input/src/index.ts new file mode 100644 index 0000000..37d9d7e --- /dev/null +++ b/typescript/audio2text-input/src/index.ts @@ -0,0 +1,17 @@ +import { ReadableApp } from "@scramjet/types"; +import { Assembly } from "../../audio2text/src/utils/assembly"; +import { Readable } from "stream"; + +const app: ReadableApp = async function(input: Readable, apiKey: string) { + const assembly = new Assembly(apiKey); + + assembly.logger.outputLogStream.pipe(this.logger.inputLogStream); + + return assembly.processFile(input).then(res => { + this.logger.info("Result", res); + + return res; + }); +}; + +export default app; diff --git a/typescript/audio2text-input/tsconfig.json b/typescript/audio2text-input/tsconfig.json new file mode 100644 index 0000000..4f0fb38 --- /dev/null +++ b/typescript/audio2text-input/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "lib": [ "ESNext" ], + "target": "ESNext", + "module": "CommonJS", + "outDir": "./dist", + "esModuleInterop": true, + "skipLibCheck": true, + "resolveJsonModule": true, + } +} diff --git a/typescript/audio2text/README.md b/typescript/audio2text/README.md index ce19253..44b8e88 100644 --- a/typescript/audio2text/README.md +++ b/typescript/audio2text/README.md @@ -36,5 +36,5 @@ si seq send dist.tar.gz si seq start - --args [\"AssemblyAi-key\"] # Transcription of the audio file as text output -si inst stdout - +si inst output - ``` diff --git a/typescript/audio2text/package.json b/typescript/audio2text/package.json index 217a026..c490393 100644 --- a/typescript/audio2text/package.json +++ b/typescript/audio2text/package.json @@ -22,12 +22,11 @@ "dependencies": { "@scramjet/obj-logger": "^0.34.3", "@scramjet/utility": "^0.33.5", - "axios": "^1.3.6", - "date-and-time": "^2.4.3", - "typescript": "^5.0.4" + "axios": "^1.3.6" }, "devDependencies": { "@scramjet/types": "0.33.5", - "@types/node": "^20.2.3" + "@types/node": "^20.2.3", + "typescript": "^5.1.6" } }