@speechall/sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ export class Configuration {
2
+ constructor(param = {}) {
3
+ this.apiKey = param.apiKey;
4
+ this.username = param.username;
5
+ this.password = param.password;
6
+ this.accessToken = param.accessToken;
7
+ this.basePath = param.basePath;
8
+ this.serverIndex = param.serverIndex;
9
+ this.baseOptions = {
10
+ ...param.baseOptions,
11
+ headers: {
12
+ ...param.baseOptions?.headers,
13
+ },
14
+ };
15
+ this.formDataCtor = param.formDataCtor;
16
+ }
17
+ isJsonMime(mime) {
18
+ const jsonMime = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
19
+ return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
20
+ }
21
+ }
@@ -0,0 +1,131 @@
1
+ import { Configuration, SpeechToTextApi, ReplacementRulesApi, TranscriptionModelIdentifier } from './index.js';
2
+ async function main() {
3
+ const config = new Configuration({
4
+ apiKey: process.env.SPEECHALL_API_KEY || 'your-api-key-here',
5
+ basePath: 'https://api.speechall.com'
6
+ });
7
+ const speechApi = new SpeechToTextApi(config);
8
+ const rulesApi = new ReplacementRulesApi(config);
9
+ try {
10
+ console.log('Fetching available models...');
11
+ const models = await speechApi.listSpeechToTextModels();
12
+ console.log('Available models:');
13
+ models.data.slice(0, 3).forEach(model => {
14
+ console.log(` - ${model.id}: ${model.display_name} (${model.provider})`);
15
+ console.log(` Languages: ${model.supported_languages?.join(', ')}`);
16
+ console.log(` Cost: $${model.cost_per_second_usd}/second\n`);
17
+ });
18
+ console.log('Example 1: Basic transcription...');
19
+ const basicOptions = {
20
+ file_url: 'https://example.com/sample-audio.mp3',
21
+ model: TranscriptionModelIdentifier.DeepgramNova2General,
22
+ language: 'en',
23
+ output_format: 'json'
24
+ };
25
+ const basicResult = await speechApi.transcribeRemote(basicOptions);
26
+ console.log('Basic transcription:', basicResult.data.text);
27
+ console.log('\nExample 2: Advanced transcription...');
28
+ const advancedOptions = {
29
+ file_url: 'https://example.com/meeting-audio.mp3',
30
+ model: TranscriptionModelIdentifier.DeepgramNova2Meeting,
31
+ language: 'en',
32
+ output_format: 'json',
33
+ diarization: true,
34
+ punctuation: true,
35
+ timestamp_granularity: 'word',
36
+ speakers_expected: 3,
37
+ custom_vocabulary: ['API', 'TypeScript', 'Speechall']
38
+ };
39
+ const advancedResult = await speechApi.transcribeRemote(advancedOptions);
40
+ console.log('Advanced transcription:', advancedResult.data.text);
41
+ console.log('\nExample 3: Creating replacement rules...');
42
+ const rulesetResponse = await rulesApi.createReplacementRuleset({
43
+ name: 'Technical Terms Enhancement',
44
+ rules: [
45
+ {
46
+ kind: 'exact',
47
+ search: 'API',
48
+ replacement: 'A.P.I.',
49
+ caseSensitive: false
50
+ },
51
+ {
52
+ kind: 'regex',
53
+ pattern: '\\b(\\d+)\\s*dollars?\\b',
54
+ replacement: '$$$1',
55
+ flags: ['i']
56
+ }
57
+ ]
58
+ });
59
+ console.log('Created ruleset with ID:', rulesetResponse.data.id);
60
+ console.log('\nExample 4: OpenAI-compatible transcription...');
61
+ console.log('OpenAI-compatible endpoint would be used here with file upload');
62
+ console.log('\nExample 5: Direct file upload transcription...');
63
+ try {
64
+ const audioData = new Uint8Array(1024);
65
+ const audioFile = new File([audioData], 'sample-audio.wav', {
66
+ type: 'audio/wav'
67
+ });
68
+ console.log('Transcribing uploaded file:', audioFile.name);
69
+ const fileResult = await speechApi.transcribe(TranscriptionModelIdentifier.DeepgramNova2General, audioFile, 'en', 'json', undefined, true, 'word', false, 'Please transcribe this audio file clearly', 0.1);
70
+ console.log('Direct file transcription result:', fileResult.data);
71
+ }
72
+ catch (error) {
73
+ console.log('File transcription example (simulated file):', error.message);
74
+ console.log('In a real implementation, you would provide actual audio file data');
75
+ }
76
+ console.log('\n--- Browser File Input Example ---');
77
+ console.log(`
78
+ // HTML:
79
+ // <input type="file" id="audioFile" accept="audio/*" />
80
+ // <button onclick="transcribeFile()">Transcribe</button>
81
+
82
+ async function transcribeFile() {
83
+ const fileInput = document.getElementById('audioFile') as HTMLInputElement;
84
+ const file = fileInput.files?.[0];
85
+
86
+ if (!file) {
87
+ alert('Please select an audio file');
88
+ return;
89
+ }
90
+
91
+ try {
92
+ const result = await speechApi.transcribe(
93
+ TranscriptionModelIdentifier.DeepgramNova2General,
94
+ file,
95
+ 'en',
96
+ 'json',
97
+ undefined, // no ruleset
98
+ true, // punctuation
99
+ 'segment', // timestamp granularity
100
+ true, // diarization
101
+ 'Transcribe this uploaded audio file' // prompt
102
+ );
103
+
104
+ console.log('Transcription:', result.data.text);
105
+
106
+ // Handle detailed response if format is 'json'
107
+ if ('segments' in result.data) {
108
+ result.data.segments?.forEach((segment, index) => {
109
+ console.log(\`Segment \${index + 1}: \${segment.text}\`);
110
+ if (segment.speaker) {
111
+ console.log(\` Speaker: \${segment.speaker}\`);
112
+ }
113
+ if (segment.start && segment.end) {
114
+ console.log(\` Time: \${segment.start}s - \${segment.end}s\`);
115
+ }
116
+ });
117
+ }
118
+ } catch (error) {
119
+ console.error('Transcription failed:', error);
120
+ }
121
+ }
122
+ `);
123
+ }
124
+ catch (error) {
125
+ console.error('Error occurred:', error.response?.data || error.message);
126
+ }
127
+ }
128
+ if (require.main === module) {
129
+ main().catch(console.error);
130
+ }
131
+ export { main as example };
@@ -0,0 +1,2 @@
1
+ export * from "./api.js";
2
+ export * from "./configuration.js";
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main as example };
3
+ //# sourceMappingURL=example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../example.ts"],"names":[],"mappings":"AAUA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAiLnC;AAOD,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,CAAC"}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.example = main;
4
+ const index_1 = require("./index");
5
+ async function main() {
6
+ const config = new index_1.Configuration({
7
+ apiKey: process.env.SPEECHALL_API_KEY || 'your-api-key-here',
8
+ basePath: 'https://api.speechall.com'
9
+ });
10
+ const speechApi = new index_1.SpeechToTextApi(config);
11
+ const rulesApi = new index_1.ReplacementRulesApi(config);
12
+ try {
13
+ console.log('Fetching available models...');
14
+ const models = await speechApi.listSpeechToTextModels();
15
+ console.log('Available models:');
16
+ models.data.slice(0, 3).forEach(model => {
17
+ console.log(` - ${model.id}: ${model.display_name} (${model.provider})`);
18
+ console.log(` Languages: ${model.supported_languages?.join(', ')}`);
19
+ console.log(` Cost: $${model.cost_per_second_usd}/second\n`);
20
+ });
21
+ console.log('Example 1: Basic transcription...');
22
+ const basicOptions = {
23
+ file_url: 'https://example.com/sample-audio.mp3',
24
+ model: index_1.TranscriptionModelIdentifier.DeepgramNova2General,
25
+ language: 'en',
26
+ output_format: 'json'
27
+ };
28
+ const basicResult = await speechApi.transcribeRemote(basicOptions);
29
+ console.log('Basic transcription:', basicResult.data.text);
30
+ console.log('\nExample 2: Advanced transcription...');
31
+ const advancedOptions = {
32
+ file_url: 'https://example.com/meeting-audio.mp3',
33
+ model: index_1.TranscriptionModelIdentifier.DeepgramNova2Meeting,
34
+ language: 'en',
35
+ output_format: 'json',
36
+ diarization: true,
37
+ punctuation: true,
38
+ timestamp_granularity: 'word',
39
+ speakers_expected: 3,
40
+ custom_vocabulary: ['API', 'TypeScript', 'Speechall']
41
+ };
42
+ const advancedResult = await speechApi.transcribeRemote(advancedOptions);
43
+ console.log('Advanced transcription:', advancedResult.data.text);
44
+ console.log('\nExample 3: Creating replacement rules...');
45
+ const rulesetResponse = await rulesApi.createReplacementRuleset({
46
+ name: 'Technical Terms Enhancement',
47
+ rules: [
48
+ {
49
+ kind: 'exact',
50
+ search: 'API',
51
+ replacement: 'A.P.I.',
52
+ caseSensitive: false
53
+ },
54
+ {
55
+ kind: 'regex',
56
+ pattern: '\\b(\\d+)\\s*dollars?\\b',
57
+ replacement: '$$$1',
58
+ flags: ['i']
59
+ }
60
+ ]
61
+ });
62
+ console.log('Created ruleset with ID:', rulesetResponse.data.id);
63
+ console.log('\nExample 4: OpenAI-compatible transcription...');
64
+ console.log('OpenAI-compatible endpoint would be used here with file upload');
65
+ console.log('\nExample 5: Direct file upload transcription...');
66
+ try {
67
+ const audioData = new Uint8Array(1024);
68
+ const audioFile = new File([audioData], 'sample-audio.wav', {
69
+ type: 'audio/wav'
70
+ });
71
+ console.log('Transcribing uploaded file:', audioFile.name);
72
+ const fileResult = await speechApi.transcribe(index_1.TranscriptionModelIdentifier.DeepgramNova2General, audioFile, 'en', 'json', undefined, true, 'word', false, 'Please transcribe this audio file clearly', 0.1);
73
+ console.log('Direct file transcription result:', fileResult.data);
74
+ }
75
+ catch (error) {
76
+ console.log('File transcription example (simulated file):', error.message);
77
+ console.log('In a real implementation, you would provide actual audio file data');
78
+ }
79
+ console.log('\n--- Browser File Input Example ---');
80
+ console.log(`
81
+ // HTML:
82
+ // <input type="file" id="audioFile" accept="audio/*" />
83
+ // <button onclick="transcribeFile()">Transcribe</button>
84
+
85
+ async function transcribeFile() {
86
+ const fileInput = document.getElementById('audioFile') as HTMLInputElement;
87
+ const file = fileInput.files?.[0];
88
+
89
+ if (!file) {
90
+ alert('Please select an audio file');
91
+ return;
92
+ }
93
+
94
+ try {
95
+ const result = await speechApi.transcribe(
96
+ TranscriptionModelIdentifier.DeepgramNova2General,
97
+ file,
98
+ 'en',
99
+ 'json',
100
+ undefined, // no ruleset
101
+ true, // punctuation
102
+ 'segment', // timestamp granularity
103
+ true, // diarization
104
+ 'Transcribe this uploaded audio file' // prompt
105
+ );
106
+
107
+ console.log('Transcription:', result.data.text);
108
+
109
+ // Handle detailed response if format is 'json'
110
+ if ('segments' in result.data) {
111
+ result.data.segments?.forEach((segment, index) => {
112
+ console.log(\`Segment \${index + 1}: \${segment.text}\`);
113
+ if (segment.speaker) {
114
+ console.log(\` Speaker: \${segment.speaker}\`);
115
+ }
116
+ if (segment.start && segment.end) {
117
+ console.log(\` Time: \${segment.start}s - \${segment.end}s\`);
118
+ }
119
+ });
120
+ }
121
+ } catch (error) {
122
+ console.error('Transcription failed:', error);
123
+ }
124
+ }
125
+ `);
126
+ }
127
+ catch (error) {
128
+ console.error('Error occurred:', error.response?.data || error.message);
129
+ }
130
+ }
131
+ if (require.main === module) {
132
+ main().catch(console.error);
133
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./api";
2
+ export * from "./configuration";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAeA,cAAc,OAAO,CAAC;AACtB,cAAc,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api"), exports);
18
+ __exportStar(require("./configuration"), exports);
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@speechall/sdk",
3
+ "version": "0.0.1",
4
+ "description": "TypeScript SDK for the Speechall API - A powerful and flexible speech-to-text service",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "module": "dist/esm/index.js",
8
+ "sideEffects": false,
9
+ "files": [
10
+ "dist/**/*",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "scripts": {
15
+ "build": "npm run build:cjs && npm run build:esm",
16
+ "build:cjs": "tsc -p tsconfig.json",
17
+ "build:esm": "tsc -p tsconfig.esm.json && node scripts/fix-esm-imports.js",
18
+ "clean": "rimraf dist",
19
+ "prepublishOnly": "npm run clean && npm run build",
20
+ "test": "echo \"Error: no test specified\" && exit 1",
21
+ "lint": "eslint . --ext .ts",
22
+ "lint:fix": "eslint . --ext .ts --fix"
23
+ },
24
+ "keywords": [
25
+ "speechall",
26
+ "speech-to-text",
27
+ "stt",
28
+ "transcription",
29
+ "audio",
30
+ "voice",
31
+ "api",
32
+ "typescript",
33
+ "sdk"
34
+ ],
35
+ "author": "Speechall",
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/speechall/speechall-typescript-sdk.git"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/speechall/speechall-typescript-sdk/issues"
43
+ },
44
+ "homepage": "https://github.com/speechall/speechall-typescript-sdk#readme",
45
+ "dependencies": {
46
+ "axios": "^1.6.0"
47
+ },
48
+ "devDependencies": {
49
+ "@semantic-release/changelog": "^6.0.3",
50
+ "@semantic-release/git": "^10.0.1",
51
+ "@types/node": "^20.0.0",
52
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
53
+ "@typescript-eslint/parser": "^6.0.0",
54
+ "eslint": "^8.0.0",
55
+ "rimraf": "^5.0.0",
56
+ "semantic-release": "^22.0.12",
57
+ "typescript": "^5.0.0"
58
+ },
59
+ "engines": {
60
+ "node": ">=16"
61
+ }
62
+ }