Skip to content

NPM Package updated for SLID (Voice, Text), OCR and Document Localiza… #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion javascript/document-localization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
### Prerequisites:

- **VS Code** installed
- **Live Server** extension installed in VS Code

### Running the Application:

Expand Down
8 changes: 4 additions & 4 deletions javascript/document-localization/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "- **VS Code** installed\r - **Live Server** extension installed in VS Code",
"main": "script.js",
"scripts": {
"start": "webpack serve --mode development",
"build": "webpack --mode production"
},
"start": "webpack serve --mode development",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
Expand All @@ -19,6 +19,6 @@
"webpack-dev-server": "^5.2.0"
},
"dependencies": {
"@reverieit/reverie-client": "^0.1.4"
"@reverieit/reverie-client": "^0.1.5"
}
}
59 changes: 59 additions & 0 deletions javascript/language-identification-text/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Identify Language by Text API

## Steps to Run the Application

### Prerequisites:

- **VS Code** installed

### Running the Application:

1. **Install Dependencies**

- Open the terminal in VS Code
- Run:
```sh
npm install
```

2. **Start the Dev Server**

- Run:
```sh
npm start
```
- This will start the Webpack Dev Server on `http://localhost:3000/`

3. **Build for Production**

- Run:
```sh
npm run build
```
- This will generate the bundled files in the `dist/` folder

4. **Using the Application**

- Enter the Text.
- View the detected language of the input text.

## API Parameters

| Parameter | Type | Required | Description |
| --------- | ------ | -------- | ------------------------------------------------ |
| `text` | String | Yes | The input text to process (Max: 512 characters). |

## Language Code

- Assamese (`as`)
- Bengali (`bn`)
- Gujarati (`gu`)
- Hindi (`hi`)
- Kannada (`kn`)
- Malayalam (`ml`)
- Marathi (`mr`)
- Odia (`or`)
- Punjabi (`pa`)
- Tamil (`ta`)
- Telugu (`te`)
- English (`en`)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!
* reverie-client
* Copyright(c) 2025 Reverie Language Technologies
* MIT Licensed
*/
1 change: 1 addition & 0 deletions javascript/language-identification-text/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Language Identification</title><script defer="defer" src="bundle.js"></script></head><body><h1>Language Identification</h1><label for="text-input">Enter text to identify language:</label> <textarea id="text-input" rows="4" cols="50" placeholder="Type your text here..."></textarea><br><br><button id="identifyLanguage">Identify Language</button><h2>Response:</h2><pre id="response-output"></pre><script src="dist/bundle.js"></script></body></html>
4 changes: 2 additions & 2 deletions javascript/language-identification-text/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ <h1>Language Identification</h1>
<label for="text-input">Enter text to identify language:</label>
<textarea id="text-input" rows="4" cols="50" placeholder="Type your text here..."></textarea><br><br>

<button onclick="identifyLanguage()">Identify Language</button>
<button id="identifyLanguage">Identify Language</button>

<h2>Response:</h2>
<pre id="response-output"></pre>

<script src="script.js"></script>
<script src="dist/bundle.js"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions javascript/language-identification-text/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "language-identification-text",
"version": "1.0.0",
"description": "",
"main": "script.js", "scripts": {
"start": "webpack serve --mode development",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^7.1.2",
"html-webpack-plugin": "^5.6.3",
"style-loader": "^4.0.0",
"webpack": "^5.98.0",
"webpack-cli": "^6.0.1",
"webpack-dev-server": "^5.2.0"
},
"dependencies": {
"@reverieit/reverie-client": "^0.1.4",
"reverie-client": "^0.1.2"
}
}
50 changes: 19 additions & 31 deletions javascript/language-identification-text/script.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import ReverieClient from "@reverieit/reverie-client";

async function identifyLanguage() {
const text = document.getElementById('text-input').value;
const apiKey = 'REV-API-KEY'; // Replace with your actual API key
const appID = 'REV-APP-ID'; // Replace with your actual app ID
const baseURL = 'https://revapi.reverieinc.com'; // Replace with the actual API base URL

// Validate text length
const reverieClient = new ReverieClient({
apiKey: "<YOUR-API-KEY>",
appId: "<YOUR-APP-ID>",
});


if (!text) {
alert('Text is required.');
return;
Expand All @@ -16,38 +19,23 @@ async function identifyLanguage() {
}

// Calculate maxLength (this is an approximation of your Go code's logic)
const maxLength = Math.pow(2, Math.ceil(Math.sqrt(text.length)));

// Prepare request body
const requestBody = {
text: text,
max_length: maxLength > 512 ? 512 : maxLength
};

try {
const response = await fetch(baseURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'REV-API-KEY': apiKey,
'REV-APP-ID': appID,
'REV-APPNAME': 'lang_id_text'
},
body: JSON.stringify(requestBody)
});

// Check if the response status is ok
if (!response.ok) {
const errorMessage = `API error: ${response.statusText}`;
document.getElementById('response-output').textContent = errorMessage;
return;
const response = await reverieClient.identify_language_by_text({ text: text });
// Extract the 'lang' field from the response
if (response.lang) {
document.getElementById('response-output').textContent = `Detected Language: ${response.lang}`;
} else {
document.getElementById('response-output').textContent = "Language could not be identified.";
}

const result = await response.json();
// Assuming the response contains a 'language' field
document.getElementById('response-output').textContent = JSON.stringify(result, null, 2);
} catch (error) {
console.error('Error:', error);
document.getElementById('response-output').textContent = 'An error occurred while identifying the language.';
}

}

document.addEventListener("DOMContentLoaded", function () {
document.getElementById("identifyLanguage").addEventListener("click", identifyLanguage);

});
32 changes: 32 additions & 0 deletions javascript/language-identification-text/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
mode: "development",
entry: './script.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
devtool: 'inline-source-map',
devServer: {
static: path.resolve(__dirname, '.'),
port: 3000,
open: true,
},
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
filename: 'index.html',
}),
],
};
59 changes: 59 additions & 0 deletions javascript/language-identification-voice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Identify Language by Voice API

## Steps to Run the Application

### Prerequisites:

- **VS Code** installed

### Running the Application:

1. **Install Dependencies**

- Open the terminal in VS Code
- Run:
```sh
npm install
```

2. **Start the Dev Server**

- Run:
```sh
npm start
```
- This will start the Webpack Dev Server on `http://localhost:3000/`

3. **Build for Production**

- Run:
```sh
npm run build
```
- This will generate the bundled files in the `dist/` folder

4. **Using the Application**

- Upload the Audio File.
- View the detected language of the audio file.

## API Parameters

| Element | Type | Description |
| ------------ | ---- | ---------------------------------------------------------------------------------------------------------------------- |
| `audio_file` | File | Local audio file’s path to obtain the transcript. **Note:** Audio file length should be **≤ 120 seconds (2 minutes).** |

## Language Code

- Assamese (`as`)
- Bengali (`bn`)
- Gujarati (`gu`)
- Hindi (`hi`)
- Kannada (`kn`)
- Malayalam (`ml`)
- Marathi (`mr`)
- Odia (`or`)
- Punjabi (`pa`)
- Tamil (`ta`)
- Telugu (`te`)
- English (`en`)
3 changes: 3 additions & 0 deletions javascript/language-identification-voice/dist/bundle.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!
* reverie-client
* Copyright(c) 2025 Reverie Language Technologies
* MIT Licensed
*/
1 change: 1 addition & 0 deletions javascript/language-identification-voice/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Audio Transcription</title><link rel="stylesheet" href="styles.css"><script src="dist/bundle.js"></script><script defer="defer" src="bundle.js"></script></head><body><div class="container"><h2>Upload Audio File</h2><input type="file" id="audioFile" accept="audio/*"> <button id="uploadBtn">Upload</button><p id="response"></p></div></body></html>
19 changes: 19 additions & 0 deletions javascript/language-identification-voice/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Audio Transcription</title>
<link rel="stylesheet" href="styles.css">
<script src="dist/bundle.js"></script>
</head>
<body>
<div class="container">
<h2>Upload Audio File</h2>
<input type="file" id="audioFile" accept="audio/*">
<button id="uploadBtn">Upload</button>
<div id="loader" class="hidden"></div>
<p id="response"></p>
</div>
</body>
</html>
24 changes: 24 additions & 0 deletions javascript/language-identification-voice/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "language-identification-voice",
"version": "1.0.0",
"description": "",
"main": "script.js",
"scripts": {
"start": "webpack serve --mode development",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^7.1.2",
"html-webpack-plugin": "^5.6.3",
"style-loader": "^4.0.0",
"webpack": "^5.98.0",
"webpack-cli": "^6.0.1",
"webpack-dev-server": "^5.2.0"
},
"dependencies": {
"@reverieit/reverie-client": "^0.1.5"
}
}
35 changes: 35 additions & 0 deletions javascript/language-identification-voice/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import ReverieClient from "@reverieit/reverie-client";

document.getElementById("uploadBtn").addEventListener("click", async () => {
const reverieClient = new ReverieClient({
apiKey: "<YOUR-API-KEY>",
appId: "<YOUR-APP-ID>",
});

const fileInput = document.getElementById("audioFile");
const loader = document.getElementById("loader");
const responseText = document.getElementById("response");

if (!fileInput.files.length) {
responseText.textContent = "Please select an audio file.";
return;
}
loader.classList.remove("hidden");

try {
const language = await reverieClient.uploadAudio({
file: fileInput.files[0],
});
if (language) {
responseText.textContent = `Language: ${language.language}`;
} else {
responseText.textContent = `Error: ${language.cause}`;
}
} catch (error) {
console.log(error);
responseText.textContent = "Upload failed. Please try again.";
}
finally {
loader.classList.add("hidden");
}
});
Loading