diff --git a/deepgram.toml b/deepgram.toml index b0cfc35..3247fc4 100644 --- a/deepgram.toml +++ b/deepgram.toml @@ -5,7 +5,7 @@ author = "Deepgram DX Team (https://developers.deepgram.co useCase = "TTS" language = "JavaScript" framework = "Node" -sdk = "4.11.2" +sdk = "5.0.0-beta.2" [pre-build] command = "pnpm run install:all" diff --git a/package.json b/package.json index 5a4587d..ef94a54 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "url": "https://github.com/deepgram-starters/node-text-to-speech.git" }, "dependencies": { - "@deepgram/sdk": "4.11.2", + "@deepgram/sdk": "5.0.0-beta.2", "dotenv": "17.2.3", "express": "5.2.1", "http-proxy-middleware": "3.0.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7b8b8b2..2e86a54 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@deepgram/sdk': - specifier: 4.11.2 - version: 4.11.2 + specifier: 5.0.0-beta.2 + version: 5.0.0-beta.2 dotenv: specifier: 17.2.3 version: 17.2.3 @@ -33,12 +33,8 @@ importers: packages: - '@deepgram/captions@1.2.0': - resolution: {integrity: sha512-8B1C/oTxTxyHlSFubAhNRgCbQ2SQ5wwvtlByn8sDYZvdDtdn/VE2yEPZ4BvUnrKWmsbTQY6/ooLV+9Ka2qmDSQ==} - engines: {node: '>=18.0.0'} - - '@deepgram/sdk@4.11.2': - resolution: {integrity: sha512-lKGxuXxlSixC8bB0BnzmIpbVjUSgYtz17cqvrgv0ZjmazgUPkuUj9egQPj6k+fbPX8wRzWEqlhrL/DXlXqeDXA==} + '@deepgram/sdk@5.0.0-beta.2': + resolution: {integrity: sha512-HucesXK3H51Xy7CE+FoZ4vGxmuEzy7q3cJpXHaE7utppy0pDMxIFc5uwJCdDE3rhZxQZNShfKKp2JjK7WDvB7A==} engines: {node: '>=18.0.0'} '@flydotio/dockerfile@0.7.10': @@ -183,9 +179,6 @@ packages: '@types/http-proxy@1.17.17': resolution: {integrity: sha512-ED6LB+Z1AVylNTu7hdzuBqOgMnvG/ld6wGCG8wFnAzKX5uyW2K3WD52v0gnLCTK/VLpXtKckgWuyScYK6cSPaw==} - '@types/node@18.19.130': - resolution: {integrity: sha512-GRaXQx6jGfL8sKfaIDD6OupbIHBr9jv7Jnaml9tB7l4v068PAOXqfcujMMo5PhbIs6ggR1XODELqahT2R8v0fg==} - '@types/node@24.10.2': resolution: {integrity: sha512-WOhQTZ4G8xZ1tjJTvKOpyEVSGgOTvJAfDK3FNFgELyaTpzhdgHVHeqW8V+UJvzF5BT+/B54T/1S2K6gd9c7bbA==} @@ -320,9 +313,6 @@ packages: resolution: {integrity: sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==} engines: {node: '>= 0.6'} - cross-fetch@3.2.0: - resolution: {integrity: sha512-Q+xVJLoGOeIMXZmbUK4HYk+69cQH6LudR0Vu/pRm2YlU/hDV9CiS0gKUMaWY5f2NeUH9C1nV3bsTlCo0FsTV1Q==} - cross-spawn@6.0.6: resolution: {integrity: sha512-VqCUuhcd1iB+dsv8gxPttb5iZh/D0iubSP21g36KXdEuf6I5JiioesUVjpCdHV9MZRUfVFlvwtIUyPfxo5trtw==} engines: {node: '>=4.8'} @@ -339,9 +329,6 @@ packages: resolution: {integrity: sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ==} engines: {node: '>= 0.4'} - dayjs@1.11.19: - resolution: {integrity: sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw==} - debug@4.4.3: resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==} engines: {node: '>=6.0'} @@ -351,10 +338,6 @@ packages: supports-color: optional: true - deepmerge@4.3.1: - resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==} - engines: {node: '>=0.10.0'} - define-data-property@1.1.4: resolution: {integrity: sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==} engines: {node: '>= 0.4'} @@ -439,10 +422,6 @@ packages: eventemitter3@4.0.7: resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} - events@3.3.0: - resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} - engines: {node: '>=0.8.x'} - express@5.2.1: resolution: {integrity: sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==} engines: {node: '>= 18'} @@ -783,15 +762,6 @@ packages: nice-try@1.0.5: resolution: {integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==} - node-fetch@2.7.0: - resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} - engines: {node: 4.x || >=6.0.0} - peerDependencies: - encoding: ^0.1.0 - peerDependenciesMeta: - encoding: - optional: true - nodemon@3.1.10: resolution: {integrity: sha512-WDjw3pJ0/0jMFmyNDp3gvY2YizjLmmOUQo6DEBY+JgdvW/yQ9mEeSw6H5ythl5Ny2ytb7f9C2nIbjSxMNzbJXw==} engines: {node: '>=10'} @@ -1083,9 +1053,6 @@ packages: resolution: {integrity: sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==} hasBin: true - tr46@0.0.3: - resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} - tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} @@ -1116,9 +1083,6 @@ packages: undefsafe@2.0.5: resolution: {integrity: sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==} - undici-types@5.26.5: - resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} - undici-types@7.16.0: resolution: {integrity: sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==} @@ -1133,12 +1097,6 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} - webidl-conversions@3.0.1: - resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} - - whatwg-url@5.0.0: - resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} - which-boxed-primitive@1.1.1: resolution: {integrity: sha512-TbX3mj8n0odCBFVlY8AxkqcHASw3L60jIuF8jFP78az3C2YhmGvqbHBpAjTRH2/xqYunrJ9g1jSyjCjpoWzIAA==} engines: {node: '>= 0.4'} @@ -1200,21 +1158,11 @@ packages: snapshots: - '@deepgram/captions@1.2.0': + '@deepgram/sdk@5.0.0-beta.2': dependencies: - dayjs: 1.11.19 - - '@deepgram/sdk@4.11.2': - dependencies: - '@deepgram/captions': 1.2.0 - '@types/node': 18.19.130 - cross-fetch: 3.2.0 - deepmerge: 4.3.1 - events: 3.3.0 ws: 8.18.3 transitivePeerDependencies: - bufferutil - - encoding - utf-8-validate '@flydotio/dockerfile@0.7.10(@types/node@24.10.2)': @@ -1357,10 +1305,6 @@ snapshots: dependencies: '@types/node': 24.10.2 - '@types/node@18.19.130': - dependencies: - undici-types: 5.26.5 - '@types/node@24.10.2': dependencies: undici-types: 7.16.0 @@ -1510,12 +1454,6 @@ snapshots: cookie@0.7.2: {} - cross-fetch@3.2.0: - dependencies: - node-fetch: 2.7.0 - transitivePeerDependencies: - - encoding - cross-spawn@6.0.6: dependencies: nice-try: 1.0.5 @@ -1542,16 +1480,12 @@ snapshots: es-errors: 1.3.0 is-data-view: 1.0.2 - dayjs@1.11.19: {} - debug@4.4.3(supports-color@5.5.0): dependencies: ms: 2.1.3 optionalDependencies: supports-color: 5.5.0 - deepmerge@4.3.1: {} - define-data-property@1.1.4: dependencies: es-define-property: 1.0.1 @@ -1678,8 +1612,6 @@ snapshots: eventemitter3@4.0.7: {} - events@3.3.0: {} - express@5.2.1: dependencies: accepts: 2.0.0 @@ -2054,10 +1986,6 @@ snapshots: nice-try@1.0.5: {} - node-fetch@2.7.0: - dependencies: - whatwg-url: 5.0.0 - nodemon@3.1.10: dependencies: chokidar: 3.6.0 @@ -2415,8 +2343,6 @@ snapshots: touch@3.1.1: {} - tr46@0.0.3: {} - tslib@2.8.1: {} type-is@2.0.1: @@ -2467,8 +2393,6 @@ snapshots: undefsafe@2.0.5: {} - undici-types@5.26.5: {} - undici-types@7.16.0: {} unpipe@1.0.0: {} @@ -2480,13 +2404,6 @@ snapshots: vary@1.1.2: {} - webidl-conversions@3.0.1: {} - - whatwg-url@5.0.0: - dependencies: - tr46: 0.0.3 - webidl-conversions: 3.0.1 - which-boxed-primitive@1.1.1: dependencies: is-bigint: 1.1.0 diff --git a/server.js b/server.js index 69af9f5..d489e28 100644 --- a/server.js +++ b/server.js @@ -15,7 +15,7 @@ require("dotenv").config(); -const { createClient } = require("@deepgram/sdk"); +const { DeepgramClient } = require("@deepgram/sdk"); const { createProxyMiddleware } = require("http-proxy-middleware"); const express = require("express"); const fs = require("fs"); @@ -89,7 +89,7 @@ const apiKey = loadApiKey(); // ============================================================================ // Initialize Deepgram client -const deepgram = createClient(apiKey); +const deepgram = new DeepgramClient({ apiKey }); // Initialize Express app const app = express(); @@ -150,15 +150,17 @@ async function streamToBuffer(stream) { */ async function generateAudio(text, model = DEFAULT_MODEL) { try { - const response = await deepgram.speak.request({ text }, { model }); - const stream = await response.getStream(); - - if (!stream) { - throw new Error("No audio stream returned from Deepgram"); - } - - const buffer = await streamToBuffer(stream); - return buffer; + // In v5, use the new API structure + const response = await deepgram.speak.v1.audio.generate({ + text, + model, + encoding: "linear16", + container: "wav" + }); + + // v5 SDK returns BinaryResponse directly with methods: stream(), arrayBuffer(), blob(), bytes() + const arrayBuffer = await response.arrayBuffer(); + return Buffer.from(arrayBuffer); } catch (error) { console.error("Error generating audio:", error); throw new Error(`Failed to generate audio: ${error.message}`);