-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project import generated by Copybara.
GitOrigin-RevId: daf91e03013775692acc0e79d886a060228c6a02
- Loading branch information
1 parent
19a807c
commit 4fb2e07
Showing
7 changed files
with
224 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"semi": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
import "dotenv/config"; | ||
import { AssemblyAI } from "assemblyai"; | ||
import { SoxRecording } from "./sox.js"; | ||
const SAMPLE_RATE = 16000; | ||
import "dotenv/config" | ||
import { AssemblyAI } from "assemblyai" | ||
import { SoxRecording } from "./sox.js" | ||
const SAMPLE_RATE = 16000 | ||
const client = new AssemblyAI({ | ||
apiKey: process.env.ASSEMBLYAI_API_KEY, | ||
}); | ||
}) | ||
const transcriber = client.realtime.transcriber({ | ||
sampleRate: SAMPLE_RATE, | ||
}); | ||
}) | ||
transcriber.on("open", ({ sessionId }) => { | ||
console.log(`Session opened with ID: ${sessionId}`); | ||
}); | ||
console.log(`Session opened with ID: ${sessionId}`) | ||
}) | ||
transcriber.on("error", (error) => { | ||
console.error("Error:", error); | ||
}); | ||
console.error("Error:", error) | ||
}) | ||
transcriber.on("close", (code, reason) => | ||
console.log("Session closed:", code, reason), | ||
); | ||
) | ||
transcriber.on("transcript", (transcript) => { | ||
if (!transcript.text) { | ||
return; | ||
return | ||
} | ||
if (transcript.message_type === "PartialTranscript") { | ||
console.log("Partial:", transcript.text); | ||
console.log("Partial:", transcript.text) | ||
} else { | ||
console.log("Final:", transcript.text); | ||
console.log("Final:", transcript.text) | ||
} | ||
}); | ||
console.log("Connecting to real-time transcript service"); | ||
await transcriber.connect(); | ||
console.log("Starting recording"); | ||
}) | ||
console.log("Connecting to real-time transcript service") | ||
await transcriber.connect() | ||
console.log("Starting recording") | ||
const recording = new SoxRecording({ | ||
channels: 1, | ||
sampleRate: SAMPLE_RATE, | ||
audioType: "wav", // Linear PCM | ||
}); | ||
recording.stream().pipeTo(transcriber.stream()); | ||
}) | ||
recording.stream().pipeTo(transcriber.stream()) | ||
// Stop recording and close connection using Ctrl-C. | ||
process.on("SIGINT", async function () { | ||
console.log(); | ||
console.log("Stopping recording"); | ||
recording.stop(); | ||
console.log("Closing real-time transcript connection"); | ||
await transcriber.close(); | ||
process.exit(); | ||
}); | ||
console.log() | ||
console.log("Stopping recording") | ||
recording.stop() | ||
console.log("Closing real-time transcript connection") | ||
await transcriber.close() | ||
process.exit() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,61 @@ | ||
import "dotenv/config"; | ||
import { AssemblyAI, RealtimeTranscript } from "assemblyai"; | ||
import { SoxRecording } from "./sox.js"; | ||
import "dotenv/config" | ||
import { AssemblyAI, RealtimeTranscript } from "assemblyai" | ||
import { SoxRecording } from "./sox.js" | ||
|
||
const SAMPLE_RATE = 16_000; | ||
const SAMPLE_RATE = 16_000 | ||
|
||
const client = new AssemblyAI({ | ||
apiKey: process.env.ASSEMBLYAI_API_KEY!, | ||
}); | ||
}) | ||
|
||
const transcriber = client.realtime.transcriber({ | ||
sampleRate: SAMPLE_RATE, | ||
}); | ||
}) | ||
|
||
transcriber.on("open", ({ sessionId }) => { | ||
console.log(`Session opened with ID: ${sessionId}`); | ||
}); | ||
console.log(`Session opened with ID: ${sessionId}`) | ||
}) | ||
|
||
transcriber.on("error", (error: Error) => { | ||
console.error("Error:", error); | ||
}); | ||
console.error("Error:", error) | ||
}) | ||
|
||
transcriber.on("close", (code: number, reason: string) => | ||
console.log("Session closed:", code, reason), | ||
); | ||
) | ||
|
||
transcriber.on("transcript", (transcript: RealtimeTranscript) => { | ||
if (!transcript.text) { | ||
return; | ||
return | ||
} | ||
|
||
if (transcript.message_type === "PartialTranscript") { | ||
console.log("Partial:", transcript.text); | ||
console.log("Partial:", transcript.text) | ||
} else { | ||
console.log("Final:", transcript.text); | ||
console.log("Final:", transcript.text) | ||
} | ||
}); | ||
}) | ||
|
||
console.log("Connecting to real-time transcript service"); | ||
await transcriber.connect(); | ||
console.log("Connecting to real-time transcript service") | ||
await transcriber.connect() | ||
|
||
console.log("Starting recording"); | ||
console.log("Starting recording") | ||
const recording = new SoxRecording({ | ||
channels: 1, | ||
sampleRate: SAMPLE_RATE, | ||
audioType: "wav", // Linear PCM | ||
}); | ||
}) | ||
|
||
recording.stream().pipeTo(transcriber.stream()); | ||
recording.stream().pipeTo(transcriber.stream()) | ||
|
||
// Stop recording and close connection using Ctrl-C. | ||
process.on("SIGINT", async function () { | ||
console.log(); | ||
console.log("Stopping recording"); | ||
recording.stop(); | ||
console.log() | ||
console.log("Stopping recording") | ||
recording.stop() | ||
|
||
console.log("Closing real-time transcript connection"); | ||
await transcriber.close(); | ||
console.log("Closing real-time transcript connection") | ||
await transcriber.close() | ||
|
||
process.exit(); | ||
}); | ||
process.exit() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.