Skip to content

Commit c27fc4f

Browse files
committed
Edits as requested
1 parent 9677a3d commit c27fc4f

File tree

3 files changed

+75
-77
lines changed

3 files changed

+75
-77
lines changed

articles/ai-services/openai/includes/text-to-speech-javascript.md

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,23 @@ recommendations: false
1414

1515
## Prerequisites
1616

17-
#### [TypeScript](#tab/typescript)
17+
#### [JavaScript](#tab/javascript)
1818

1919
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
2020
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
21-
- [TypeScript](https://www.typescriptlang.org/download/)
2221
- An Azure OpenAI resource created in a supported region (see [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability)). For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
2322

2423

25-
#### [JavaScript](#tab/javascript)
24+
#### [TypeScript](#tab/typescript)
2625

2726
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
2827
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
28+
- [TypeScript](https://www.typescriptlang.org/download/)
2929
- An Azure OpenAI resource created in a supported region (see [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability)). For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
3030

31-
---
32-
33-
34-
## Passwordless authentication is recommended
3531

36-
For passwordless authentication, you need to
3732

38-
1. Use the `@azure/identity` package.
39-
1. Assign the `Cognitive Services User` role to your user account. This can be done in the Azure portal under **Access control (IAM)** > **Add role assignment**.
40-
1. Sign in with the Azure CLI such as `az login`.
33+
---
4134

4235
## Set up
4336

@@ -112,16 +105,16 @@ Your app's _package.json_ file will be updated with the dependencies.
112105
## Create a speech file
113106

114107

115-
#### [TypeScript](#tab/typescript)
116108

117-
1. Create a new file named _Text-to-speech.ts_ and open it in your preferred code editor. Copy the following code into the _Text-to-speech.ts_ file:
109+
#### [JavaScript](#tab/javascript)
118110

119-
```typescript
120-
import "dotenv/config";
121-
import { writeFile } from "fs/promises";
122-
import { AzureOpenAI } from "openai";
123-
import type { SpeechCreateParams } from "openai/resources/audio/speech";
124-
import "openai/shims/node";
111+
1. Create a new file named _Text-to-speech.js_ and open it in your preferred code editor. Copy the following code into the _Text-to-speech.js_ file:
112+
113+
```javascript
114+
require("dotenv/config");
115+
const { writeFile } = require("fs/promises");
116+
const { AzureOpenAI } = require("openai");
117+
require("openai/shims/node");
125118

126119
// You will need to set these environment variables or edit the following values
127120
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "<endpoint>";
@@ -133,7 +126,7 @@ Your app's _package.json_ file will be updated with the dependencies.
133126
const deploymentName = "tts";
134127
const apiVersion = "2024-07-01-preview";
135128

136-
function getClient(): AzureOpenAI {
129+
function getClient() {
137130
return new AzureOpenAI({
138131
endpoint,
139132
apiKey,
@@ -143,9 +136,9 @@ Your app's _package.json_ file will be updated with the dependencies.
143136
}
144137

145138
async function generateAudioStream(
146-
client: AzureOpenAI,
147-
params: SpeechCreateParams
148-
): Promise<NodeJS.ReadableStream> {
139+
client,
140+
params
141+
) {
149142
const response = await client.audio.speech.create(params);
150143
if (response.ok) return response.body;
151144
throw new Error(`Failed to generate audio stream: ${response.statusText}`);
@@ -170,31 +163,24 @@ Your app's _package.json_ file will be updated with the dependencies.
170163
});
171164

172165
```
173-
174-
The "openai/shims/node" import supports the ability for the a stream type that changes depending on whether you run in Node.js or in another environment such as a browser.
175166

176-
1. Build the application with the following command:
177-
178-
```console
179-
tsc
180-
```
181-
182-
1. Run the application with the following command:
167+
1. Run the script with the following command:
183168

184169
```console
185170
node Text-to-speech.js
186171
```
172+
187173

174+
#### [TypeScript](#tab/typescript)
188175

189-
#### [JavaScript](#tab/javascript)
190-
191-
1. Create a new file named _Text-to-speech.js_ and open it in your preferred code editor. Copy the following code into the _Text-to-speech.js_ file:
176+
1. Create a new file named _Text-to-speech.ts_ and open it in your preferred code editor. Copy the following code into the _Text-to-speech.ts_ file:
192177

193-
```javascript
194-
require("dotenv/config");
195-
const { writeFile } = require("fs/promises");
196-
const { AzureOpenAI } = require("openai");
197-
require("openai/shims/node");
178+
```typescript
179+
import "dotenv/config";
180+
import { writeFile } from "fs/promises";
181+
import { AzureOpenAI } from "openai";
182+
import type { SpeechCreateParams } from "openai/resources/audio/speech";
183+
import "openai/shims/node";
198184
199185
// You will need to set these environment variables or edit the following values
200186
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "<endpoint>";
@@ -206,7 +192,7 @@ Your app's _package.json_ file will be updated with the dependencies.
206192
const deploymentName = "tts";
207193
const apiVersion = "2024-07-01-preview";
208194
209-
function getClient() {
195+
function getClient(): AzureOpenAI {
210196
return new AzureOpenAI({
211197
endpoint,
212198
apiKey,
@@ -216,9 +202,9 @@ Your app's _package.json_ file will be updated with the dependencies.
216202
}
217203
218204
async function generateAudioStream(
219-
client,
220-
params
221-
) {
205+
client: AzureOpenAI,
206+
params: SpeechCreateParams
207+
): Promise<NodeJS.ReadableStream> {
222208
const response = await client.audio.speech.create(params);
223209
if (response.ok) return response.body;
224210
throw new Error(`Failed to generate audio stream: ${response.statusText}`);
@@ -243,11 +229,19 @@ Your app's _package.json_ file will be updated with the dependencies.
243229
});
244230
245231
```
232+
233+
The "openai/shims/node" import supports the ability for the a stream type that changes depending on whether you run in Node.js or in another environment such as a browser.
234+
235+
1. Build the application with the following command:
236+
237+
```console
238+
tsc
239+
```
246240

247-
1. Run the script with the following command:
241+
1. Run the application with the following command:
248242

249243
```console
250244
node Text-to-speech.js
251245
```
252-
246+
253247
---

articles/ai-services/openai/includes/whisper-javascript.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ author: eric-urban
1313

1414
## Prerequisites
1515

16-
#### [TypeScript](#tab/typescript)
16+
#### [JavaScript](#tab/javascript)
1717

1818
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
1919
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
20-
- [TypeScript](https://www.typescriptlang.org/download/)
2120
- An Azure OpenAI resource created in a supported region (see [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability)). For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
2221

2322

24-
#### [JavaScript](#tab/javascript)
23+
24+
#### [TypeScript](#tab/typescript)
2525

2626
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
2727
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
28+
- [TypeScript](https://www.typescriptlang.org/download/)
2829
- An Azure OpenAI resource created in a supported region (see [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability)). For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
2930

31+
3032
---
3133

3234

@@ -111,14 +113,15 @@ Your app's _package.json_ file will be updated with the dependencies.
111113

112114
## Create a sample application
113115

114-
#### [TypeScript](#tab/typescript)
116+
117+
#### [JavaScript](#tab/javascript)
115118

116119
1. Create a new file named _Whisper.js_ and open it in your preferred code editor. Copy the following code into the _Whisper.js_ file:
117-
118-
```typescript
119-
import "dotenv/config";
120-
import { createReadStream } from "fs";
121-
import { AzureOpenAI } from "openai";
120+
121+
```javascript
122+
require("dotenv/config");
123+
const { createReadStream } = require("fs");
124+
const { AzureOpenAI } = require("openai");
122125

123126
// You will need to set these environment variables or edit the following values
124127
const audioFilePath = process.env["AUDIO_FILE_PATH"] || "<audio file path>";
@@ -129,7 +132,7 @@ Your app's _package.json_ file will be updated with the dependencies.
129132
const apiVersion = "2024-07-01-preview";
130133
const deploymentName = "whisper";
131134

132-
function getClient(): AzureOpenAI {
135+
function getClient() {
133136
return new AzureOpenAI({
134137
endpoint,
135138
apiKey,
@@ -155,26 +158,21 @@ Your app's _package.json_ file will be updated with the dependencies.
155158
});
156159
```
157160

158-
1. Build the application with the following command:
159-
160-
```console
161-
tsc
162-
```
163-
164-
1. Run the application with the following command:
161+
1. Run the script with the following command:
165162

166163
```console
167164
node Whisper.js
168165
```
169166

170-
#### [JavaScript](#tab/javascript)
171167

172-
1. Create a new file named _Whisper.js_ and open it in your preferred code editor. Copy the following code into the _Whisper.js_ file:
168+
#### [TypeScript](#tab/typescript)
173169

174-
```javascript
175-
require("dotenv/config");
176-
const { createReadStream } = require("fs");
177-
const { AzureOpenAI } = require("openai");
170+
1. Create a new file named _Whisper.js_ and open it in your preferred code editor. Copy the following code into the _Whisper.js_ file:
171+
172+
```typescript
173+
import "dotenv/config";
174+
import { createReadStream } from "fs";
175+
import { AzureOpenAI } from "openai";
178176
179177
// You will need to set these environment variables or edit the following values
180178
const audioFilePath = process.env["AUDIO_FILE_PATH"] || "<audio file path>";
@@ -185,7 +183,7 @@ Your app's _package.json_ file will be updated with the dependencies.
185183
const apiVersion = "2024-07-01-preview";
186184
const deploymentName = "whisper";
187185
188-
function getClient() {
186+
function getClient(): AzureOpenAI {
189187
return new AzureOpenAI({
190188
endpoint,
191189
apiKey,
@@ -211,7 +209,13 @@ Your app's _package.json_ file will be updated with the dependencies.
211209
});
212210
```
213211

214-
1. Run the script with the following command:
212+
1. Build the application with the following command:
213+
214+
```console
215+
tsc
216+
```
217+
218+
1. Run the application with the following command:
215219

216220
```console
217221
node Whisper.js

zone-pivots/zone-pivot-groups.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,14 @@ groups:
231231
title: Programming languages
232232
prompt: Choose a programming language
233233
pivots:
234-
- id: rest-api
235-
title: REST
236-
- id: programming-language-powershell
237-
title: PowerShell
238-
- id: programming-language-python
239-
title: Python
240234
- id: programming-language-javascript
241235
title: JavaScript
236+
- id: programming-language-python
237+
title: Python
238+
- id: programming-language-powershell
239+
title: PowerShell
240+
- id: rest-api
241+
title: REST
242242
# Owner: diberry
243243
- id: programming-languages-set-six
244244
title: Programming languages

0 commit comments

Comments
 (0)