sarvamai 0.1.6-b1 → 0.1.6
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/dist/cjs/Client.d.ts +3 -0
- package/dist/cjs/Client.js +7 -2
- package/dist/cjs/api/resources/index.d.ts +1 -0
- package/dist/cjs/api/resources/index.js +2 -1
- package/dist/cjs/api/resources/textToSpeech/client/requests/TextToSpeechRequest.d.ts +2 -0
- package/dist/cjs/api/resources/textToSpeechStreaming/client/Client.d.ts +34 -0
- package/dist/cjs/api/resources/textToSpeechStreaming/client/Client.js +83 -0
- package/dist/cjs/api/resources/textToSpeechStreaming/client/Socket.d.ts +55 -0
- package/dist/cjs/api/resources/textToSpeechStreaming/client/Socket.js +170 -0
- package/dist/cjs/api/resources/textToSpeechStreaming/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/textToSpeechStreaming/client/index.js +2 -0
- package/dist/cjs/api/resources/textToSpeechStreaming/index.d.ts +1 -0
- package/dist/cjs/api/resources/textToSpeechStreaming/index.js +17 -0
- package/dist/cjs/api/types/AudioCodec.d.ts +17 -0
- package/dist/cjs/api/types/AudioCodec.js +16 -0
- package/dist/cjs/api/types/AudioOutput.d.ts +15 -0
- package/dist/cjs/api/types/AudioOutput.js +5 -0
- package/dist/cjs/api/types/ConfigureConnection.d.ts +121 -0
- package/dist/cjs/api/types/ConfigureConnection.js +41 -0
- package/dist/cjs/api/types/ErrorResponse.d.ts +16 -0
- package/dist/cjs/api/types/ErrorResponse.js +5 -0
- package/dist/cjs/api/types/FlushSignal.d.ts +10 -0
- package/dist/cjs/api/types/FlushSignal.js +5 -0
- package/dist/cjs/api/types/PingSignal.d.ts +10 -0
- package/dist/cjs/api/types/PingSignal.js +5 -0
- package/dist/cjs/api/types/SendText.d.ts +12 -0
- package/dist/cjs/api/types/SendText.js +5 -0
- package/dist/cjs/api/types/SpeechToTextModel.d.ts +3 -1
- package/dist/cjs/api/types/SpeechToTextModel.js +2 -0
- package/dist/cjs/api/types/SpeechToTextTranslateModel.d.ts +3 -1
- package/dist/cjs/api/types/SpeechToTextTranslateModel.js +2 -0
- package/dist/cjs/api/types/index.d.ts +7 -0
- package/dist/cjs/api/types/index.js +7 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.d.mts +3 -0
- package/dist/esm/Client.mjs +7 -2
- package/dist/esm/api/resources/index.d.mts +1 -0
- package/dist/esm/api/resources/index.mjs +1 -0
- package/dist/esm/api/resources/textToSpeech/client/requests/TextToSpeechRequest.d.mts +2 -0
- package/dist/esm/api/resources/textToSpeechStreaming/client/Client.d.mts +34 -0
- package/dist/esm/api/resources/textToSpeechStreaming/client/Client.mjs +46 -0
- package/dist/esm/api/resources/textToSpeechStreaming/client/Socket.d.mts +55 -0
- package/dist/esm/api/resources/textToSpeechStreaming/client/Socket.mjs +133 -0
- package/dist/esm/api/resources/textToSpeechStreaming/client/index.d.mts +1 -0
- package/dist/esm/api/resources/textToSpeechStreaming/client/index.mjs +1 -0
- package/dist/esm/api/resources/textToSpeechStreaming/index.d.mts +1 -0
- package/dist/esm/api/resources/textToSpeechStreaming/index.mjs +1 -0
- package/dist/esm/api/types/AudioCodec.d.mts +17 -0
- package/dist/esm/api/types/AudioCodec.mjs +13 -0
- package/dist/esm/api/types/AudioOutput.d.mts +15 -0
- package/dist/esm/api/types/AudioOutput.mjs +4 -0
- package/dist/esm/api/types/ConfigureConnection.d.mts +121 -0
- package/dist/esm/api/types/ConfigureConnection.mjs +38 -0
- package/dist/esm/api/types/ErrorResponse.d.mts +16 -0
- package/dist/esm/api/types/ErrorResponse.mjs +4 -0
- package/dist/esm/api/types/FlushSignal.d.mts +10 -0
- package/dist/esm/api/types/FlushSignal.mjs +4 -0
- package/dist/esm/api/types/PingSignal.d.mts +10 -0
- package/dist/esm/api/types/PingSignal.mjs +4 -0
- package/dist/esm/api/types/SendText.d.mts +12 -0
- package/dist/esm/api/types/SendText.mjs +4 -0
- package/dist/esm/api/types/SpeechToTextModel.d.mts +3 -1
- package/dist/esm/api/types/SpeechToTextModel.mjs +2 -0
- package/dist/esm/api/types/SpeechToTextTranslateModel.d.mts +3 -1
- package/dist/esm/api/types/SpeechToTextTranslateModel.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +7 -0
- package/dist/esm/api/types/index.mjs +7 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
package/dist/cjs/Client.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { TextToSpeech } from "./api/resources/textToSpeech/client/Client.js";
|
|
|
9
9
|
import { Chat } from "./api/resources/chat/client/Client.js";
|
|
10
10
|
import { SpeechToTextStreaming } from "./api/resources/speechToTextStreaming/client/Client.js";
|
|
11
11
|
import { SpeechToTextTranslateStreaming } from "./api/resources/speechToTextTranslateStreaming/client/Client.js";
|
|
12
|
+
import { TextToSpeechStreaming } from "./api/resources/textToSpeechStreaming/client/Client.js";
|
|
12
13
|
export declare namespace SarvamAIClient {
|
|
13
14
|
interface Options {
|
|
14
15
|
environment?: core.Supplier<environments.SarvamAIEnvironment | environments.SarvamAIEnvironmentUrls>;
|
|
@@ -37,6 +38,7 @@ export declare class SarvamAIClient {
|
|
|
37
38
|
protected _chat: Chat | undefined;
|
|
38
39
|
protected _speechToTextStreaming: SpeechToTextStreaming | undefined;
|
|
39
40
|
protected _speechToTextTranslateStreaming: SpeechToTextTranslateStreaming | undefined;
|
|
41
|
+
protected _textToSpeechStreaming: TextToSpeechStreaming | undefined;
|
|
40
42
|
constructor(_options?: SarvamAIClient.Options);
|
|
41
43
|
get text(): Text;
|
|
42
44
|
get speechToText(): SpeechToText;
|
|
@@ -44,4 +46,5 @@ export declare class SarvamAIClient {
|
|
|
44
46
|
get chat(): Chat;
|
|
45
47
|
get speechToTextStreaming(): SpeechToTextStreaming;
|
|
46
48
|
get speechToTextTranslateStreaming(): SpeechToTextTranslateStreaming;
|
|
49
|
+
get textToSpeechStreaming(): TextToSpeechStreaming;
|
|
47
50
|
}
|
package/dist/cjs/Client.js
CHANGED
|
@@ -45,13 +45,14 @@ const Client_js_3 = require("./api/resources/textToSpeech/client/Client.js");
|
|
|
45
45
|
const Client_js_4 = require("./api/resources/chat/client/Client.js");
|
|
46
46
|
const Client_js_5 = require("./api/resources/speechToTextStreaming/client/Client.js");
|
|
47
47
|
const Client_js_6 = require("./api/resources/speechToTextTranslateStreaming/client/Client.js");
|
|
48
|
+
const Client_js_7 = require("./api/resources/textToSpeechStreaming/client/Client.js");
|
|
48
49
|
class SarvamAIClient {
|
|
49
50
|
constructor(_options = {}) {
|
|
50
51
|
this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
|
|
51
52
|
"X-Fern-Language": "JavaScript",
|
|
52
53
|
"X-Fern-SDK-Name": "sarvamai",
|
|
53
|
-
"X-Fern-SDK-Version": "0.1.6
|
|
54
|
-
"User-Agent": "sarvamai/0.1.6
|
|
54
|
+
"X-Fern-SDK-Version": "0.1.6",
|
|
55
|
+
"User-Agent": "sarvamai/0.1.6",
|
|
55
56
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
56
57
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
57
58
|
}, _options === null || _options === void 0 ? void 0 : _options.headers) });
|
|
@@ -80,5 +81,9 @@ class SarvamAIClient {
|
|
|
80
81
|
var _a;
|
|
81
82
|
return ((_a = this._speechToTextTranslateStreaming) !== null && _a !== void 0 ? _a : (this._speechToTextTranslateStreaming = new Client_js_6.SpeechToTextTranslateStreaming(this._options)));
|
|
82
83
|
}
|
|
84
|
+
get textToSpeechStreaming() {
|
|
85
|
+
var _a;
|
|
86
|
+
return ((_a = this._textToSpeechStreaming) !== null && _a !== void 0 ? _a : (this._textToSpeechStreaming = new Client_js_7.TextToSpeechStreaming(this._options)));
|
|
87
|
+
}
|
|
83
88
|
}
|
|
84
89
|
exports.SarvamAIClient = SarvamAIClient;
|
|
@@ -2,6 +2,7 @@ export * as speechToTextStreaming from "./speechToTextStreaming/index.js";
|
|
|
2
2
|
export * from "./speechToTextStreaming/types/index.js";
|
|
3
3
|
export * as speechToTextTranslateStreaming from "./speechToTextTranslateStreaming/index.js";
|
|
4
4
|
export * from "./speechToTextTranslateStreaming/types/index.js";
|
|
5
|
+
export * as textToSpeechStreaming from "./textToSpeechStreaming/index.js";
|
|
5
6
|
export * as text from "./text/index.js";
|
|
6
7
|
export * as speechToText from "./speechToText/index.js";
|
|
7
8
|
export * as textToSpeech from "./textToSpeech/index.js";
|
|
@@ -36,11 +36,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
36
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.chat = exports.textToSpeech = exports.speechToText = exports.text = exports.speechToTextTranslateStreaming = exports.speechToTextStreaming = void 0;
|
|
39
|
+
exports.chat = exports.textToSpeech = exports.speechToText = exports.text = exports.textToSpeechStreaming = exports.speechToTextTranslateStreaming = exports.speechToTextStreaming = void 0;
|
|
40
40
|
exports.speechToTextStreaming = __importStar(require("./speechToTextStreaming/index.js"));
|
|
41
41
|
__exportStar(require("./speechToTextStreaming/types/index.js"), exports);
|
|
42
42
|
exports.speechToTextTranslateStreaming = __importStar(require("./speechToTextTranslateStreaming/index.js"));
|
|
43
43
|
__exportStar(require("./speechToTextTranslateStreaming/types/index.js"), exports);
|
|
44
|
+
exports.textToSpeechStreaming = __importStar(require("./textToSpeechStreaming/index.js"));
|
|
44
45
|
exports.text = __importStar(require("./text/index.js"));
|
|
45
46
|
exports.speechToText = __importStar(require("./speechToText/index.js"));
|
|
46
47
|
exports.textToSpeech = __importStar(require("./textToSpeech/index.js"));
|
|
@@ -38,4 +38,6 @@ export interface TextToSpeechRequest {
|
|
|
38
38
|
enable_preprocessing?: boolean;
|
|
39
39
|
/** Specifies the model to use for text-to-speech conversion. Default is bulbul:v2. */
|
|
40
40
|
model?: SarvamAI.TextToSpeechModel;
|
|
41
|
+
/** Specifies the audio codec for the output audio file. Different codecs offer various compression and quality characteristics. */
|
|
42
|
+
audio_codec?: SarvamAI.AudioCodec;
|
|
41
43
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
import * as environments from "../../../../environments.js";
|
|
5
|
+
import * as core from "../../../../core/index.js";
|
|
6
|
+
import { TextToSpeechStreamingSocket } from "./Socket.js";
|
|
7
|
+
export declare namespace TextToSpeechStreaming {
|
|
8
|
+
interface Options {
|
|
9
|
+
environment?: core.Supplier<environments.SarvamAIEnvironment | environments.SarvamAIEnvironmentUrls>;
|
|
10
|
+
/** Specify a custom URL to connect the client to. */
|
|
11
|
+
baseUrl?: core.Supplier<string>;
|
|
12
|
+
apiSubscriptionKey?: core.Supplier<string>;
|
|
13
|
+
/** Additional headers to include in requests. */
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
15
|
+
}
|
|
16
|
+
interface ConnectArgs {
|
|
17
|
+
model?: "bulbul:v2" | undefined;
|
|
18
|
+
"Api-Subscription-Key"?: string;
|
|
19
|
+
/** Arbitrary headers to send with the websocket connect request. */
|
|
20
|
+
headers?: Record<string, unknown>;
|
|
21
|
+
/** Enable debug mode on the websocket. Defaults to false. */
|
|
22
|
+
debug?: boolean;
|
|
23
|
+
/** Number of reconnect attempts. Defaults to 30. */
|
|
24
|
+
reconnectAttempts?: number;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export declare class TextToSpeechStreaming {
|
|
28
|
+
protected readonly _options: TextToSpeechStreaming.Options;
|
|
29
|
+
constructor(_options?: TextToSpeechStreaming.Options);
|
|
30
|
+
connect(args?: TextToSpeechStreaming.ConnectArgs): Promise<TextToSpeechStreamingSocket>;
|
|
31
|
+
protected _getCustomAuthorizationHeaders(): Promise<{
|
|
32
|
+
"api-subscription-key": string | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
39
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
40
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
41
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
42
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
43
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
44
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.TextToSpeechStreaming = void 0;
|
|
49
|
+
const environments = __importStar(require("../../../../environments.js"));
|
|
50
|
+
const core = __importStar(require("../../../../core/index.js"));
|
|
51
|
+
const qs = __importStar(require("qs"));
|
|
52
|
+
const Socket_js_1 = require("./Socket.js");
|
|
53
|
+
class TextToSpeechStreaming {
|
|
54
|
+
constructor(_options = {}) {
|
|
55
|
+
this._options = _options;
|
|
56
|
+
}
|
|
57
|
+
connect() {
|
|
58
|
+
return __awaiter(this, arguments, void 0, function* (args = {}) {
|
|
59
|
+
var _a, _b, _c, _d, _e;
|
|
60
|
+
const queryParams = {};
|
|
61
|
+
if (args["model"] != null) {
|
|
62
|
+
queryParams["model"] = args["model"];
|
|
63
|
+
}
|
|
64
|
+
let websocketHeaders = {};
|
|
65
|
+
websocketHeaders = Object.assign(Object.assign({}, websocketHeaders), (yield this._getCustomAuthorizationHeaders()));
|
|
66
|
+
if (args["Api-Subscription-Key"] != null) {
|
|
67
|
+
websocketHeaders["Api-Subscription-Key"] = args["Api-Subscription-Key"];
|
|
68
|
+
}
|
|
69
|
+
websocketHeaders = Object.assign(Object.assign({}, websocketHeaders), args["headers"]);
|
|
70
|
+
const apiSubscriptionKeyValue = (_a = (yield core.Supplier.get(this._options.apiSubscriptionKey))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env["SARVAM_API_KEY"];
|
|
71
|
+
const socket = new core.ReconnectingWebSocket(`${(_b = (yield core.Supplier.get(this._options["baseUrl"]))) !== null && _b !== void 0 ? _b : ((_c = (yield core.Supplier.get(this._options["environment"]))) !== null && _c !== void 0 ? _c : environments.SarvamAIEnvironment.Production).production}/text-to-speech/ws?${qs.stringify(queryParams, { arrayFormat: "repeat" })}`, [`api-subscription-key.${apiSubscriptionKeyValue}`], { debug: (_d = args["debug"]) !== null && _d !== void 0 ? _d : false, maxRetries: (_e = args["reconnectAttempts"]) !== null && _e !== void 0 ? _e : 30 }, websocketHeaders);
|
|
72
|
+
return new Socket_js_1.TextToSpeechStreamingSocket({ socket });
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
_getCustomAuthorizationHeaders() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
var _a;
|
|
78
|
+
const apiSubscriptionKeyValue = (_a = (yield core.Supplier.get(this._options.apiSubscriptionKey))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env["SARVAM_API_KEY"];
|
|
79
|
+
return { "api-subscription-key": apiSubscriptionKeyValue };
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.TextToSpeechStreaming = TextToSpeechStreaming;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
import * as core from "../../../../core/index.js";
|
|
5
|
+
import * as SarvamAI from "../../../index.js";
|
|
6
|
+
export declare namespace TextToSpeechStreamingSocket {
|
|
7
|
+
interface Args {
|
|
8
|
+
socket: core.ReconnectingWebSocket;
|
|
9
|
+
}
|
|
10
|
+
type Response = SarvamAI.AudioOutput | SarvamAI.ErrorResponse;
|
|
11
|
+
type EventHandlers = {
|
|
12
|
+
open?: () => void;
|
|
13
|
+
message?: (message: Response) => void;
|
|
14
|
+
close?: (event: core.CloseEvent) => void;
|
|
15
|
+
error?: (error: Error) => void;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare class TextToSpeechStreamingSocket {
|
|
19
|
+
readonly socket: core.ReconnectingWebSocket;
|
|
20
|
+
protected readonly eventHandlers: TextToSpeechStreamingSocket.EventHandlers;
|
|
21
|
+
private handleOpen;
|
|
22
|
+
private handleMessage;
|
|
23
|
+
private handleClose;
|
|
24
|
+
private handleError;
|
|
25
|
+
constructor(args: TextToSpeechStreamingSocket.Args);
|
|
26
|
+
/** The current state of the connection; this is one of the readyState constants. */
|
|
27
|
+
get readyState(): number;
|
|
28
|
+
/**
|
|
29
|
+
* @param event - The event to attach to.
|
|
30
|
+
* @param callback - The callback to run when the event is triggered.
|
|
31
|
+
* Usage:
|
|
32
|
+
* ```typescript
|
|
33
|
+
* this.on('open', () => {
|
|
34
|
+
* console.log('The websocket is open');
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
on<T extends keyof TextToSpeechStreamingSocket.EventHandlers>(event: T, callback: TextToSpeechStreamingSocket.EventHandlers[T]): void;
|
|
39
|
+
configureConnection(message: SarvamAI.ConfigureConnection): void;
|
|
40
|
+
convert(text: string): void;
|
|
41
|
+
flush(): void;
|
|
42
|
+
ping(): void;
|
|
43
|
+
/** Connect to the websocket and register event handlers. */
|
|
44
|
+
connect(): TextToSpeechStreamingSocket;
|
|
45
|
+
/** Close the websocket and unregister event handlers. */
|
|
46
|
+
close(): void;
|
|
47
|
+
/** Returns a promise that resolves when the websocket is open. */
|
|
48
|
+
waitForOpen(): Promise<core.ReconnectingWebSocket>;
|
|
49
|
+
/** Asserts that the websocket is open. */
|
|
50
|
+
private assertSocketIsOpen;
|
|
51
|
+
/** Send a binary payload to the websocket. */
|
|
52
|
+
private sendBinary;
|
|
53
|
+
/** Send a JSON payload to the websocket. */
|
|
54
|
+
private sendJson;
|
|
55
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
39
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
40
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
41
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
42
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
43
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
44
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.TextToSpeechStreamingSocket = void 0;
|
|
49
|
+
const core = __importStar(require("../../../../core/index.js"));
|
|
50
|
+
const json_js_1 = require("../../../../core/json.js");
|
|
51
|
+
class TextToSpeechStreamingSocket {
|
|
52
|
+
constructor(args) {
|
|
53
|
+
this.eventHandlers = {};
|
|
54
|
+
this.handleOpen = () => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
(_b = (_a = this.eventHandlers).open) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
57
|
+
};
|
|
58
|
+
this.handleMessage = (event) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
const data = (0, json_js_1.fromJson)(event.data);
|
|
61
|
+
(_b = (_a = this.eventHandlers).message) === null || _b === void 0 ? void 0 : _b.call(_a, data);
|
|
62
|
+
};
|
|
63
|
+
this.handleClose = (event) => {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
(_b = (_a = this.eventHandlers).close) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
66
|
+
};
|
|
67
|
+
this.handleError = (event) => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
const message = event.message;
|
|
70
|
+
(_b = (_a = this.eventHandlers).error) === null || _b === void 0 ? void 0 : _b.call(_a, new Error(message));
|
|
71
|
+
};
|
|
72
|
+
this.socket = args.socket;
|
|
73
|
+
this.socket.addEventListener("open", this.handleOpen);
|
|
74
|
+
this.socket.addEventListener("message", this.handleMessage);
|
|
75
|
+
this.socket.addEventListener("close", this.handleClose);
|
|
76
|
+
this.socket.addEventListener("error", this.handleError);
|
|
77
|
+
}
|
|
78
|
+
/** The current state of the connection; this is one of the readyState constants. */
|
|
79
|
+
get readyState() {
|
|
80
|
+
return this.socket.readyState;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @param event - The event to attach to.
|
|
84
|
+
* @param callback - The callback to run when the event is triggered.
|
|
85
|
+
* Usage:
|
|
86
|
+
* ```typescript
|
|
87
|
+
* this.on('open', () => {
|
|
88
|
+
* console.log('The websocket is open');
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
on(event, callback) {
|
|
93
|
+
this.eventHandlers[event] = callback;
|
|
94
|
+
}
|
|
95
|
+
configureConnection(message) {
|
|
96
|
+
this.assertSocketIsOpen();
|
|
97
|
+
this.sendJson(message);
|
|
98
|
+
}
|
|
99
|
+
convert(text) {
|
|
100
|
+
this.assertSocketIsOpen();
|
|
101
|
+
const message = {
|
|
102
|
+
type: "text",
|
|
103
|
+
data: { text },
|
|
104
|
+
};
|
|
105
|
+
this.sendJson(message);
|
|
106
|
+
}
|
|
107
|
+
flush() {
|
|
108
|
+
this.assertSocketIsOpen();
|
|
109
|
+
const message = { type: "flush" };
|
|
110
|
+
this.sendJson(message);
|
|
111
|
+
}
|
|
112
|
+
ping() {
|
|
113
|
+
this.assertSocketIsOpen();
|
|
114
|
+
const message = { type: "ping" };
|
|
115
|
+
this.sendJson(message);
|
|
116
|
+
}
|
|
117
|
+
/** Connect to the websocket and register event handlers. */
|
|
118
|
+
connect() {
|
|
119
|
+
this.socket.reconnect();
|
|
120
|
+
this.socket.addEventListener("open", this.handleOpen);
|
|
121
|
+
this.socket.addEventListener("message", this.handleMessage);
|
|
122
|
+
this.socket.addEventListener("close", this.handleClose);
|
|
123
|
+
this.socket.addEventListener("error", this.handleError);
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
/** Close the websocket and unregister event handlers. */
|
|
127
|
+
close() {
|
|
128
|
+
this.socket.close();
|
|
129
|
+
this.handleClose({ code: 1000 });
|
|
130
|
+
this.socket.removeEventListener("open", this.handleOpen);
|
|
131
|
+
this.socket.removeEventListener("message", this.handleMessage);
|
|
132
|
+
this.socket.removeEventListener("close", this.handleClose);
|
|
133
|
+
this.socket.removeEventListener("error", this.handleError);
|
|
134
|
+
}
|
|
135
|
+
/** Returns a promise that resolves when the websocket is open. */
|
|
136
|
+
waitForOpen() {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
if (this.socket.readyState === core.ReconnectingWebSocket.OPEN) {
|
|
139
|
+
return this.socket;
|
|
140
|
+
}
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
this.socket.addEventListener("open", () => {
|
|
143
|
+
resolve(this.socket);
|
|
144
|
+
});
|
|
145
|
+
this.socket.addEventListener("error", (event) => {
|
|
146
|
+
reject(event);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/** Asserts that the websocket is open. */
|
|
152
|
+
assertSocketIsOpen() {
|
|
153
|
+
if (!this.socket) {
|
|
154
|
+
throw new Error("Socket is not connected.");
|
|
155
|
+
}
|
|
156
|
+
if (this.socket.readyState !== core.ReconnectingWebSocket.OPEN) {
|
|
157
|
+
throw new Error("Socket is not open.");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Send a binary payload to the websocket. */
|
|
161
|
+
sendBinary(payload) {
|
|
162
|
+
this.socket.send(payload);
|
|
163
|
+
}
|
|
164
|
+
/** Send a JSON payload to the websocket. */
|
|
165
|
+
sendJson(payload) {
|
|
166
|
+
const jsonPayload = (0, json_js_1.toJson)(payload);
|
|
167
|
+
this.socket.send(jsonPayload);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.TextToSpeechStreamingSocket = TextToSpeechStreamingSocket;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./client/index.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./client/index.js"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Audio codec options for the non-streaming /text-to-speech endpoint
|
|
6
|
+
*/
|
|
7
|
+
export type AudioCodec = "mp3" | "linear16" | "mulaw" | "alaw" | "opus" | "flac" | "aac" | "wav";
|
|
8
|
+
export declare const AudioCodec: {
|
|
9
|
+
readonly Mp3: "mp3";
|
|
10
|
+
readonly Linear16: "linear16";
|
|
11
|
+
readonly Mulaw: "mulaw";
|
|
12
|
+
readonly Alaw: "alaw";
|
|
13
|
+
readonly Opus: "opus";
|
|
14
|
+
readonly Flac: "flac";
|
|
15
|
+
readonly Aac: "aac";
|
|
16
|
+
readonly Wav: "wav";
|
|
17
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AudioCodec = void 0;
|
|
7
|
+
exports.AudioCodec = {
|
|
8
|
+
Mp3: "mp3",
|
|
9
|
+
Linear16: "linear16",
|
|
10
|
+
Mulaw: "mulaw",
|
|
11
|
+
Alaw: "alaw",
|
|
12
|
+
Opus: "opus",
|
|
13
|
+
Flac: "flac",
|
|
14
|
+
Aac: "aac",
|
|
15
|
+
Wav: "wav",
|
|
16
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
export interface AudioOutput {
|
|
5
|
+
type: "audio";
|
|
6
|
+
data: AudioOutput.Data;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace AudioOutput {
|
|
9
|
+
interface Data {
|
|
10
|
+
/** MIME type of the audio content (e.g., 'audio/mp3', 'audio/wav') */
|
|
11
|
+
content_type: string;
|
|
12
|
+
/** Base64-encoded audio data ready for playback or download */
|
|
13
|
+
audio: string;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Configuration message required as the first message after establishing the WebSocket connection.
|
|
6
|
+
* This initializes TTS parameters and can be updated at any time during the WebSocket lifecycle
|
|
7
|
+
* by sending a new config message. When a config update is sent, any text currently in the buffer
|
|
8
|
+
* will be automatically flushed and processed before applying the new configuration.
|
|
9
|
+
*/
|
|
10
|
+
export interface ConfigureConnection {
|
|
11
|
+
type: "config";
|
|
12
|
+
data: ConfigureConnection.Data;
|
|
13
|
+
}
|
|
14
|
+
export declare namespace ConfigureConnection {
|
|
15
|
+
interface Data {
|
|
16
|
+
/** The language of the text is BCP-47 format */
|
|
17
|
+
target_language_code: Data.TargetLanguageCode;
|
|
18
|
+
/**
|
|
19
|
+
* The speaker voice to be used for the output audio.
|
|
20
|
+
*
|
|
21
|
+
* **Default:** Anushka
|
|
22
|
+
*
|
|
23
|
+
* **Model Compatibility (Speakers compatible with respective model):**
|
|
24
|
+
* - **bulbul:v2:**
|
|
25
|
+
* - Female: Anushka, Manisha, Vidya, Arya
|
|
26
|
+
* - Male: Abhilash, Karun, Hitesh
|
|
27
|
+
*
|
|
28
|
+
* **Note:** Speaker selection must match the chosen model version.
|
|
29
|
+
*/
|
|
30
|
+
speaker: Data.Speaker;
|
|
31
|
+
/**
|
|
32
|
+
* Controls the pitch of the audio. Lower values result in a deeper voice,
|
|
33
|
+
* while higher values make it sharper. The suitable range is between -0.75
|
|
34
|
+
* and 0.75. Default is 0.0.
|
|
35
|
+
*/
|
|
36
|
+
pitch?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Controls the speed of the audio. Lower values result in slower speech,
|
|
39
|
+
* while higher values make it faster. The suitable range is between 0.5
|
|
40
|
+
* and 2.0. Default is 1.0.
|
|
41
|
+
*/
|
|
42
|
+
pace?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Controls the loudness of the audio. Lower values result in quieter audio,
|
|
45
|
+
* while higher values make it louder. The suitable range is between 0.3
|
|
46
|
+
* and 3.0. Default is 1.0.
|
|
47
|
+
*/
|
|
48
|
+
loudness?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Specifies the sample rate of the output audio. Supported values are
|
|
51
|
+
* 8000, 16000, 22050, 24000 Hz. If not provided, the default is 22050 Hz.
|
|
52
|
+
*/
|
|
53
|
+
speech_sample_rate?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Controls whether normalization of English words and numeric entities
|
|
56
|
+
* (e.g., numbers, dates) is performed. Set to true for better handling
|
|
57
|
+
* of mixed-language text. Default is false.
|
|
58
|
+
*/
|
|
59
|
+
enable_preprocessing?: boolean;
|
|
60
|
+
/** Audio codec (currently supports MP3 only, optimized for real-time playback) */
|
|
61
|
+
output_audio_codec?: "mp3";
|
|
62
|
+
/** Audio bitrate (choose from 5 supported bitrate options) */
|
|
63
|
+
output_audio_bitrate?: Data.OutputAudioBitrate;
|
|
64
|
+
/** Minimum character length that triggers buffer flushing for TTS model processing */
|
|
65
|
+
min_buffer_size?: number;
|
|
66
|
+
/** Maximum length for sentence splitting (adjust based on content length) */
|
|
67
|
+
max_chunk_length?: number;
|
|
68
|
+
}
|
|
69
|
+
namespace Data {
|
|
70
|
+
/**
|
|
71
|
+
* The language of the text is BCP-47 format
|
|
72
|
+
*/
|
|
73
|
+
type TargetLanguageCode = "bn-IN" | "en-IN" | "gu-IN" | "hi-IN" | "kn-IN" | "ml-IN" | "mr-IN" | "od-IN" | "pa-IN" | "ta-IN" | "te-IN";
|
|
74
|
+
const TargetLanguageCode: {
|
|
75
|
+
readonly BnIn: "bn-IN";
|
|
76
|
+
readonly EnIn: "en-IN";
|
|
77
|
+
readonly GuIn: "gu-IN";
|
|
78
|
+
readonly HiIn: "hi-IN";
|
|
79
|
+
readonly KnIn: "kn-IN";
|
|
80
|
+
readonly MlIn: "ml-IN";
|
|
81
|
+
readonly MrIn: "mr-IN";
|
|
82
|
+
readonly OdIn: "od-IN";
|
|
83
|
+
readonly PaIn: "pa-IN";
|
|
84
|
+
readonly TaIn: "ta-IN";
|
|
85
|
+
readonly TeIn: "te-IN";
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The speaker voice to be used for the output audio.
|
|
89
|
+
*
|
|
90
|
+
* **Default:** Anushka
|
|
91
|
+
*
|
|
92
|
+
* **Model Compatibility (Speakers compatible with respective model):**
|
|
93
|
+
* - **bulbul:v2:**
|
|
94
|
+
* - Female: Anushka, Manisha, Vidya, Arya
|
|
95
|
+
* - Male: Abhilash, Karun, Hitesh
|
|
96
|
+
*
|
|
97
|
+
* **Note:** Speaker selection must match the chosen model version.
|
|
98
|
+
*/
|
|
99
|
+
type Speaker = "anushka" | "abhilash" | "manisha" | "vidya" | "arya" | "karun" | "hitesh";
|
|
100
|
+
const Speaker: {
|
|
101
|
+
readonly Anushka: "anushka";
|
|
102
|
+
readonly Abhilash: "abhilash";
|
|
103
|
+
readonly Manisha: "manisha";
|
|
104
|
+
readonly Vidya: "vidya";
|
|
105
|
+
readonly Arya: "arya";
|
|
106
|
+
readonly Karun: "karun";
|
|
107
|
+
readonly Hitesh: "hitesh";
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Audio bitrate (choose from 5 supported bitrate options)
|
|
111
|
+
*/
|
|
112
|
+
type OutputAudioBitrate = "32k" | "64k" | "96k" | "128k" | "192k";
|
|
113
|
+
const OutputAudioBitrate: {
|
|
114
|
+
readonly ThirtyTwoK: "32k";
|
|
115
|
+
readonly SixtyFourK: "64k";
|
|
116
|
+
readonly NinetySixK: "96k";
|
|
117
|
+
readonly OneHundredTwentyEightK: "128k";
|
|
118
|
+
readonly OneHundredNinetyTwoK: "192k";
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|