-
Notifications
You must be signed in to change notification settings - Fork 5.5k
OpenAI Speech to Text / Create Transcription #16544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
components/openai/actions/create-transcription/create-transcription.mjs
This file contains hidden or 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,115 @@ | ||
| import openai from "../../openai.app.mjs"; | ||
| import FormData from "form-data"; | ||
| import fs from "fs"; | ||
|
|
||
| export default { | ||
| key: "openai-create-transcription", | ||
| name: "Create Transcription", | ||
| description: "Transcribes audio into the input language. [See the documentation](https://platform.openai.com/docs/api-reference/audio/createTranscription)", | ||
| version: "0.2.0", | ||
| type: "action", | ||
| props: { | ||
| openai, | ||
| file: { | ||
| propDefinition: [ | ||
| openai, | ||
| "file", | ||
| ], | ||
| }, | ||
| model: { | ||
| type: "string", | ||
| label: "Model", | ||
| description: "ID of the model to use", | ||
| options: [ | ||
| "gpt-4o-transcribe", | ||
| "gpt-4o-mini-transcribe", | ||
| "whisper-1", | ||
| ], | ||
| }, | ||
| include: { | ||
| type: "string[]", | ||
| label: "Include", | ||
| description: "Additional information to include in the transcription response. `logprobs` will return the log probabilities of the tokens in the response to understand the model's confidence in the transcription. `logprobs` only works with response_format set to `json` and only with the models `gpt-4o-transcribe` and `gpt-4o-mini-transcribe`.", | ||
| optional: true, | ||
| }, | ||
| language: { | ||
| type: "string", | ||
| label: "Language", | ||
| description: "The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. en) format will improve accuracy and latency.", | ||
| default: "en", | ||
| optional: true, | ||
| }, | ||
| prompt: { | ||
| type: "string", | ||
| label: "Prompt", | ||
| description: "An optional text to guide the model's style or continue a previous audio segment. The [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should match the audio language.", | ||
| optional: true, | ||
| }, | ||
| response_format: { | ||
| type: "string", | ||
| label: "Response Format", | ||
| description: "The format of the output. For `gpt-4o-transcribe` and `gpt-4o-mini-transcribe`, the only supported format is `json`.", | ||
| options: [ | ||
| "json", | ||
| "text", | ||
| "srt", | ||
| "verbose_json", | ||
| "vtt", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| temperature: { | ||
| type: "string", | ||
| label: "Temperature", | ||
| description: "The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.", | ||
| optional: true, | ||
| }, | ||
| timestamp_granularities: { | ||
| type: "string[]", | ||
| label: "Timestamp Granularities", | ||
| description: "The timestamp granularities to populate for this transcription. `response_format` must be set `verbose_json` to use timestamp granularities. Either or both of these options are supported: `word`, or `segment`. Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| createTranscription(opts = {}) { | ||
| return this.openai._makeRequest({ | ||
| method: "POST", | ||
| path: "/audio/transcriptions", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| /* eslint-disable no-unused-vars */ | ||
| openai, | ||
| file, | ||
| createTranscription, | ||
| ...fields | ||
| } = this; | ||
|
|
||
| const data = new FormData(); | ||
| const content = fs.createReadStream(file.includes("tmp/") | ||
| ? file | ||
| : `/tmp/${file}`); | ||
|
|
||
| data.append("file", content); | ||
|
|
||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(fields)) { | ||
| data.append(key, value); | ||
| } | ||
|
|
||
| const response = await createTranscription({ | ||
| $, | ||
| data, | ||
| headers: data.getHeaders(), | ||
| }); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $.export("$summary", "Successfully converted speech to text"); | ||
| return response; | ||
| }, | ||
| }; | ||
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.