Skip to content

Commit

Permalink
Merge branch 'main' into feat/slack-addon
Browse files Browse the repository at this point in the history
  • Loading branch information
gzukowski committed Jul 6, 2023
2 parents ae6f412 + 284c877 commit 1b8ac25
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 8 deletions.
8 changes: 5 additions & 3 deletions python/audio2text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.<br/>
The audio file
<a href="https://salford.figshare.com/collections/HARVARD_speech_corpus_-_audio_recording_2019/4437578" target="_blank">`song.wav`</a> is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License.

___

Expand All @@ -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 <Sequence-id> 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 <Sequence-id> --args [\"<AssemblyAi-key>\"]
si seq start <Sequence-id> --args [\"<AssemblyAI-token>\"]

# Transcription of the audio file as text output
si inst output <Instance-id>
Expand Down
60 changes: 60 additions & 0 deletions typescript/audio2text-event/README.md
Original file line number Diff line number Diff line change
@@ -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
<a href="https://salford.figshare.com/collections/HARVARD_speech_corpus_-_audio_recording_2019/4437578" target="_blank">`song.wav`</a> 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 <instance-id> pause` to pause input stream and `si inst event emit <instance-id> 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)
33 changes: 33 additions & 0 deletions typescript/audio2text-event/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Binary file added typescript/audio2text-event/song.wav
Binary file not shown.
45 changes: 45 additions & 0 deletions typescript/audio2text-event/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { ReadableApp } from "@scramjet/types";
import { Assembly } from "../../audio2text/src/utils/assembly";
import { PassThrough } from "stream";

const app: ReadableApp<any> = 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;
11 changes: 11 additions & 0 deletions typescript/audio2text-event/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"lib": [ "ESNext" ],
"target": "ESNext",
"module": "CommonJS",
"outDir": "./dist",
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
}
}
62 changes: 62 additions & 0 deletions typescript/audio2text-input/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Audio2text Input

This is another version which uses input channel instead of filesystem

The audio file
<a href="https://salford.figshare.com/collections/HARVARD_speech_corpus_-_audio_recording_2019/4437578" target="_blank">`song.wav`</a> 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 <Sequence-id> value
si seq send dist.tar.gz

# Start a Sequence, with the AssemblyAi-key as an argument parameter
si seq start <Sequence-id> --args [\"<AssemblyAI-token>\"]

# 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)
33 changes: 33 additions & 0 deletions typescript/audio2text-input/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Binary file added typescript/audio2text-input/song.wav
Binary file not shown.
17 changes: 17 additions & 0 deletions typescript/audio2text-input/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ReadableApp } from "@scramjet/types";
import { Assembly } from "../../audio2text/src/utils/assembly";
import { Readable } from "stream";

const app: ReadableApp<any> = 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;
11 changes: 11 additions & 0 deletions typescript/audio2text-input/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"lib": [ "ESNext" ],
"target": "ESNext",
"module": "CommonJS",
"outDir": "./dist",
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
}
}
2 changes: 1 addition & 1 deletion typescript/audio2text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
```
7 changes: 3 additions & 4 deletions typescript/audio2text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 1b8ac25

Please sign in to comment.