@speechall/sdk 1.0.0 → 2.0.4
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.
- package/.beads/README.md +81 -0
- package/.beads/config.yaml +62 -0
- package/.beads/issues.jsonl +46 -0
- package/.beads/metadata.json +4 -0
- package/.env.example +5 -0
- package/.fernignore +45 -0
- package/.gitattributes +3 -0
- package/.github/copilot-instructions.md +78 -0
- package/.github/workflows/auto-release-simple.yml.deprecated +106 -0
- package/.github/workflows/auto-release.yml +67 -0
- package/.github/workflows/ci.yml +41 -0
- package/.github/workflows/release.yml +57 -0
- package/AGENTS.md +94 -0
- package/CHANGELOG.md +58 -0
- package/CLAUDE.md +75 -0
- package/README.md +294 -155
- package/examples/CLAUDE.md +136 -0
- package/examples/advanced-options.ts +213 -0
- package/examples/basic-transcription.ts +66 -0
- package/examples/error-handling.ts +251 -0
- package/examples/list-models.ts +112 -0
- package/examples/remote-transcription.ts +60 -0
- package/fern/fern.config.json +4 -0
- package/fern/generators.yml +43 -0
- package/jest.config.js +11 -0
- package/package.json +26 -46
- package/regenerate.sh +45 -0
- package/scripts/fix-generated-code.sh +25 -0
- package/src/BaseClient.ts +82 -0
- package/src/Client.ts +30 -0
- package/src/api/errors/BadRequestError.ts +22 -0
- package/src/api/errors/GatewayTimeoutError.ts +22 -0
- package/src/api/errors/InternalServerError.ts +22 -0
- package/src/api/errors/NotFoundError.ts +22 -0
- package/src/api/errors/PaymentRequiredError.ts +22 -0
- package/src/api/errors/ServiceUnavailableError.ts +22 -0
- package/src/api/errors/TooManyRequestsError.ts +22 -0
- package/src/api/errors/UnauthorizedError.ts +22 -0
- package/src/api/errors/index.ts +8 -0
- package/src/api/index.ts +3 -0
- package/src/api/resources/index.ts +5 -0
- package/src/api/resources/replacementRules/client/Client.ts +148 -0
- package/src/api/resources/replacementRules/client/index.ts +1 -0
- package/src/api/resources/replacementRules/client/requests/CreateReplacementRulesetRequest.ts +25 -0
- package/src/api/resources/replacementRules/client/requests/index.ts +1 -0
- package/src/api/resources/replacementRules/index.ts +2 -0
- package/src/api/resources/replacementRules/types/CreateReplacementRulesetResponse.ts +6 -0
- package/src/api/resources/replacementRules/types/index.ts +1 -0
- package/src/api/resources/speechToText/client/Client.ts +275 -0
- package/src/api/resources/speechToText/client/index.ts +1 -0
- package/src/api/resources/speechToText/client/requests/RemoteTranscriptionConfiguration.ts +20 -0
- package/src/api/resources/speechToText/client/requests/TranscribeRequest.ts +26 -0
- package/src/api/resources/speechToText/client/requests/index.ts +2 -0
- package/src/api/resources/speechToText/index.ts +1 -0
- package/src/api/types/BaseTranscriptionConfiguration.ts +29 -0
- package/src/api/types/ErrorResponse.ts +11 -0
- package/src/api/types/ExactRule.ts +13 -0
- package/src/api/types/RegexGroupRule.ts +28 -0
- package/src/api/types/RegexRule.ts +28 -0
- package/src/api/types/ReplacementRule.ts +25 -0
- package/src/api/types/SpeechToTextModel.ts +90 -0
- package/src/api/types/TranscriptLanguageCode.ts +114 -0
- package/src/api/types/TranscriptOutputFormat.ts +18 -0
- package/src/api/types/TranscriptionDetailed.ts +19 -0
- package/src/api/types/TranscriptionModelIdentifier.ts +80 -0
- package/src/api/types/TranscriptionOnlyText.ts +11 -0
- package/src/api/types/TranscriptionProvider.ts +23 -0
- package/src/api/types/TranscriptionResponse.ts +8 -0
- package/src/api/types/TranscriptionSegment.ts +17 -0
- package/src/api/types/TranscriptionWord.ts +17 -0
- package/src/api/types/index.ts +16 -0
- package/src/auth/BearerAuthProvider.ts +37 -0
- package/src/auth/index.ts +1 -0
- package/src/core/auth/AuthProvider.ts +6 -0
- package/src/core/auth/AuthRequest.ts +9 -0
- package/src/core/auth/BasicAuth.ts +32 -0
- package/src/core/auth/BearerToken.ts +20 -0
- package/src/core/auth/NoOpAuthProvider.ts +8 -0
- package/src/core/auth/index.ts +5 -0
- package/src/core/base64.ts +27 -0
- package/src/core/exports.ts +2 -0
- package/src/core/fetcher/APIResponse.ts +23 -0
- package/src/core/fetcher/BinaryResponse.ts +34 -0
- package/src/core/fetcher/EndpointMetadata.ts +13 -0
- package/src/core/fetcher/EndpointSupplier.ts +14 -0
- package/src/core/fetcher/Fetcher.ts +391 -0
- package/src/core/fetcher/Headers.ts +93 -0
- package/src/core/fetcher/HttpResponsePromise.ts +116 -0
- package/src/core/fetcher/RawResponse.ts +61 -0
- package/src/core/fetcher/Supplier.ts +11 -0
- package/src/core/fetcher/createRequestUrl.ts +6 -0
- package/src/core/fetcher/getErrorResponseBody.ts +33 -0
- package/src/core/fetcher/getFetchFn.ts +3 -0
- package/src/core/fetcher/getHeader.ts +8 -0
- package/src/core/fetcher/getRequestBody.ts +20 -0
- package/src/core/fetcher/getResponseBody.ts +58 -0
- package/src/core/fetcher/index.ts +11 -0
- package/src/core/fetcher/makeRequest.ts +42 -0
- package/src/core/fetcher/requestWithRetries.ts +64 -0
- package/src/core/fetcher/signals.ts +26 -0
- package/src/core/file/exports.ts +1 -0
- package/src/core/file/file.ts +217 -0
- package/src/core/file/index.ts +2 -0
- package/src/core/file/types.ts +81 -0
- package/src/core/headers.ts +35 -0
- package/src/core/index.ts +7 -0
- package/src/core/json.ts +27 -0
- package/src/core/logging/exports.ts +19 -0
- package/src/core/logging/index.ts +1 -0
- package/src/core/logging/logger.ts +203 -0
- package/src/core/runtime/index.ts +1 -0
- package/src/core/runtime/runtime.ts +134 -0
- package/src/core/url/encodePathParam.ts +18 -0
- package/src/core/url/index.ts +3 -0
- package/src/core/url/join.ts +79 -0
- package/src/core/url/qs.ts +74 -0
- package/src/environments.ts +7 -0
- package/src/errors/SpeechallError.ts +58 -0
- package/src/errors/SpeechallTimeoutError.ts +13 -0
- package/src/errors/handleNonStatusCodeError.ts +37 -0
- package/src/errors/index.ts +2 -0
- package/src/exports.ts +1 -0
- package/src/index.ts +6 -0
- package/test-import.ts +17 -0
- package/tests/integration/api.test.ts +93 -0
- package/tests/unit/client.test.ts +91 -0
- package/tsconfig.json +20 -0
- package/dist/api.d.ts +0 -501
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js +0 -610
- package/dist/base.d.ts +0 -32
- package/dist/base.d.ts.map +0 -1
- package/dist/base.js +0 -35
- package/dist/common.d.ts +0 -14
- package/dist/common.d.ts.map +0 -1
- package/dist/common.js +0 -91
- package/dist/configuration.d.ts +0 -23
- package/dist/configuration.d.ts.map +0 -1
- package/dist/configuration.js +0 -25
- package/dist/esm/api.js +0 -592
- package/dist/esm/base.js +0 -27
- package/dist/esm/common.js +0 -79
- package/dist/esm/configuration.js +0 -21
- package/dist/esm/example.js +0 -131
- package/dist/esm/index.js +0 -2
- package/dist/example.d.ts +0 -3
- package/dist/example.d.ts.map +0 -1
- package/dist/example.js +0 -133
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -18
package/dist/esm/common.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { RequiredError } from "./base.js";
|
|
2
|
-
export const DUMMY_BASE_URL = 'https://example.com';
|
|
3
|
-
export const assertParamExists = function (functionName, paramName, paramValue) {
|
|
4
|
-
if (paramValue === null || paramValue === undefined) {
|
|
5
|
-
throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
export const setApiKeyToObject = async function (object, keyParamName, configuration) {
|
|
9
|
-
if (configuration && configuration.apiKey) {
|
|
10
|
-
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
|
|
11
|
-
? await configuration.apiKey(keyParamName)
|
|
12
|
-
: await configuration.apiKey;
|
|
13
|
-
object[keyParamName] = localVarApiKeyValue;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
export const setBasicAuthToObject = function (object, configuration) {
|
|
17
|
-
if (configuration && (configuration.username || configuration.password)) {
|
|
18
|
-
object["auth"] = { username: configuration.username, password: configuration.password };
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
export const setBearerAuthToObject = async function (object, configuration) {
|
|
22
|
-
if (configuration && configuration.accessToken) {
|
|
23
|
-
const accessToken = typeof configuration.accessToken === 'function'
|
|
24
|
-
? await configuration.accessToken()
|
|
25
|
-
: await configuration.accessToken;
|
|
26
|
-
object["Authorization"] = "Bearer " + accessToken;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
export const setOAuthToObject = async function (object, name, scopes, configuration) {
|
|
30
|
-
if (configuration && configuration.accessToken) {
|
|
31
|
-
const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
|
|
32
|
-
? await configuration.accessToken(name, scopes)
|
|
33
|
-
: await configuration.accessToken;
|
|
34
|
-
object["Authorization"] = "Bearer " + localVarAccessTokenValue;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
|
|
38
|
-
if (parameter == null)
|
|
39
|
-
return;
|
|
40
|
-
if (typeof parameter === "object") {
|
|
41
|
-
if (Array.isArray(parameter)) {
|
|
42
|
-
parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
Object.keys(parameter).forEach(currentKey => setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
if (urlSearchParams.has(key)) {
|
|
50
|
-
urlSearchParams.append(key, parameter);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
urlSearchParams.set(key, parameter);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export const setSearchParams = function (url, ...objects) {
|
|
58
|
-
const searchParams = new URLSearchParams(url.search);
|
|
59
|
-
setFlattenedQueryParams(searchParams, objects);
|
|
60
|
-
url.search = searchParams.toString();
|
|
61
|
-
};
|
|
62
|
-
export const serializeDataIfNeeded = function (value, requestOptions, configuration) {
|
|
63
|
-
const nonString = typeof value !== 'string';
|
|
64
|
-
const needsSerialization = nonString && configuration && configuration.isJsonMime
|
|
65
|
-
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
|
|
66
|
-
: nonString;
|
|
67
|
-
return needsSerialization
|
|
68
|
-
? JSON.stringify(value !== undefined ? value : {})
|
|
69
|
-
: (value || "");
|
|
70
|
-
};
|
|
71
|
-
export const toPathString = function (url) {
|
|
72
|
-
return url.pathname + url.search + url.hash;
|
|
73
|
-
};
|
|
74
|
-
export const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) {
|
|
75
|
-
return (axios = globalAxios, basePath = BASE_PATH) => {
|
|
76
|
-
const axiosRequestArgs = { ...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url };
|
|
77
|
-
return axios.request(axiosRequestArgs);
|
|
78
|
-
};
|
|
79
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/esm/example.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
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 };
|
package/dist/esm/index.js
DELETED
package/dist/example.d.ts
DELETED
package/dist/example.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/example.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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);
|