-
Notifications
You must be signed in to change notification settings - Fork 57.7k
feat(MiniMax Node): Add standalone MiniMax vendor node #28748
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 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f750271
feat(MiniMax Node): Add standalone MiniMax vendor node
DawidMyslak 9ec856f
fix(MiniMax Node): Fix lint errors in option ordering and description
DawidMyslak 8157c96
Merge branch 'master' into node-4760-minimax-standalone-node
DawidMyslak e985961
Merge branch 'master' into node-4760-minimax-standalone-node
DawidMyslak 67533b2
fix(MiniMax Node): Remove unused helper, fix voice docs URL
DawidMyslak 9e4d2dd
fix(MiniMax Node): Address review feedback - seed filter, TTS dead co…
DawidMyslak 3870943
Merge branch 'master' into node-4760-minimax-standalone-node
michael-radency 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
12 changes: 12 additions & 0 deletions
12
packages/@n8n/nodes-langchain/nodes/vendors/MiniMax/MiniMax.node.ts
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,12 @@ | ||
| import type { IExecuteFunctions, INodeType } from 'n8n-workflow'; | ||
|
|
||
| import { router } from './actions/router'; | ||
| import { versionDescription } from './actions/versionDescription'; | ||
|
|
||
| export class MiniMax implements INodeType { | ||
| description = versionDescription; | ||
|
|
||
| async execute(this: IExecuteFunctions) { | ||
| return await router.call(this); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
packages/@n8n/nodes-langchain/nodes/vendors/MiniMax/actions/audio/index.ts
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,29 @@ | ||
| import type { INodeProperties } from 'n8n-workflow'; | ||
|
|
||
| import * as textToSpeech from './tts.operation'; | ||
|
|
||
| export { textToSpeech }; | ||
|
|
||
| export const description: INodeProperties[] = [ | ||
| { | ||
| displayName: 'Operation', | ||
| name: 'operation', | ||
| type: 'options', | ||
| noDataExpression: true, | ||
| displayOptions: { | ||
| show: { | ||
| resource: ['audio'], | ||
| }, | ||
| }, | ||
| options: [ | ||
| { | ||
| name: 'Text to Speech', | ||
| value: 'textToSpeech', | ||
| action: 'Convert text to speech', | ||
| description: 'Generate speech audio from text input', | ||
| }, | ||
| ], | ||
| default: 'textToSpeech', | ||
| }, | ||
| ...textToSpeech.description, | ||
| ]; |
290 changes: 290 additions & 0 deletions
290
packages/@n8n/nodes-langchain/nodes/vendors/MiniMax/actions/audio/tts.operation.ts
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,290 @@ | ||
| import type { | ||
| IDataObject, | ||
| IExecuteFunctions, | ||
| INodeExecutionData, | ||
| INodeProperties, | ||
| } from 'n8n-workflow'; | ||
| import { NodeOperationError, updateDisplayOptions } from 'n8n-workflow'; | ||
|
|
||
| import type { T2AResponse } from '../../helpers/interfaces'; | ||
| import { apiRequest } from '../../transport'; | ||
|
|
||
| const properties: INodeProperties[] = [ | ||
| { | ||
| displayName: 'Model', | ||
| name: 'modelId', | ||
| type: 'options', | ||
| options: [ | ||
| { | ||
| name: 'Speech 02 HD', | ||
| value: 'speech-02-hd', | ||
| description: 'Superior rhythm and stability with outstanding quality', | ||
| }, | ||
| { | ||
| name: 'Speech 02 Turbo', | ||
| value: 'speech-02-turbo', | ||
| description: 'Enhanced multilingual capabilities and performance', | ||
| }, | ||
| { | ||
| name: 'Speech 2.6 HD', | ||
| value: 'speech-2.6-hd', | ||
| description: 'HD model with outstanding prosody and cloning similarity', | ||
| }, | ||
| { | ||
| name: 'Speech 2.6 Turbo', | ||
| value: 'speech-2.6-turbo', | ||
| description: 'Turbo model with support for 40 languages', | ||
| }, | ||
| { | ||
| name: 'Speech 2.8 HD', | ||
| value: 'speech-2.8-hd', | ||
| description: 'Latest HD model with ultra-realistic quality and sound tags', | ||
| }, | ||
| { | ||
| name: 'Speech 2.8 Turbo', | ||
| value: 'speech-2.8-turbo', | ||
| description: 'Latest Turbo model with seamless speed and natural flow', | ||
| }, | ||
| ], | ||
| default: 'speech-2.8-hd', | ||
| description: 'The speech synthesis model to use', | ||
| }, | ||
| { | ||
| displayName: 'Text', | ||
| name: 'text', | ||
| type: 'string', | ||
| typeOptions: { | ||
| rows: 4, | ||
| }, | ||
| default: '', | ||
| required: true, | ||
| description: 'The text to convert to speech (max 10,000 characters)', | ||
| placeholder: 'e.g. Hello, welcome to our service!', | ||
| }, | ||
| { | ||
| displayName: 'Voice ID', | ||
| name: 'voiceId', | ||
| type: 'string', | ||
| default: 'English_Graceful_Lady', | ||
| required: true, | ||
| // eslint-disable-next-line n8n-nodes-base/node-param-description-miscased-id | ||
| description: | ||
| 'Voice ID to use for speech synthesis. Browse available voices in the <a href="https://platform.minimax.io/docs/faq/system-voice-id">MiniMax documentation</a>.', | ||
| placeholder: 'e.g. English_Graceful_Lady', | ||
| }, | ||
| { | ||
| displayName: 'Download Audio', | ||
| name: 'downloadAudio', | ||
| type: 'boolean', | ||
| default: true, | ||
| description: | ||
| 'Whether to download the generated audio as binary data. When disabled, only the audio URL is returned.', | ||
| }, | ||
| { | ||
| displayName: 'Options', | ||
| name: 'options', | ||
| placeholder: 'Add Option', | ||
| type: 'collection', | ||
| default: {}, | ||
| options: [ | ||
| { | ||
| displayName: 'Audio Format', | ||
| name: 'audioFormat', | ||
| type: 'options', | ||
| options: [ | ||
| { name: 'MP3', value: 'mp3' }, | ||
| { name: 'PCM', value: 'pcm' }, | ||
| { name: 'FLAC', value: 'flac' }, | ||
| { name: 'WAV', value: 'wav' }, | ||
| ], | ||
| default: 'mp3', | ||
| description: 'Output audio format. WAV is only supported in non-streaming mode.', | ||
| }, | ||
| { | ||
| displayName: 'Emotion', | ||
| name: 'emotion', | ||
| type: 'options', | ||
| options: [ | ||
| { name: 'Angry', value: 'angry' }, | ||
| { name: 'Calm', value: 'calm' }, | ||
| { name: 'Disgusted', value: 'disgusted' }, | ||
| { name: 'Fearful', value: 'fearful' }, | ||
| { name: 'Happy', value: 'happy' }, | ||
| { name: 'Sad', value: 'sad' }, | ||
| { name: 'Surprised', value: 'surprised' }, | ||
| ], | ||
| default: 'calm', | ||
| description: | ||
| 'Emotion for synthesized speech. By default the model auto-selects the most natural emotion.', | ||
| }, | ||
| { | ||
| displayName: 'Language Boost', | ||
| name: 'languageBoost', | ||
| type: 'options', | ||
| options: [ | ||
| { name: 'Arabic', value: 'Arabic' }, | ||
| { name: 'Auto Detect', value: 'auto' }, | ||
| { name: 'Chinese', value: 'Chinese' }, | ||
| { name: 'English', value: 'English' }, | ||
| { name: 'French', value: 'French' }, | ||
| { name: 'German', value: 'German' }, | ||
| { name: 'Indonesian', value: 'Indonesian' }, | ||
| { name: 'Italian', value: 'Italian' }, | ||
| { name: 'Japanese', value: 'Japanese' }, | ||
| { name: 'Korean', value: 'Korean' }, | ||
| { name: 'Portuguese', value: 'Portuguese' }, | ||
| { name: 'Russian', value: 'Russian' }, | ||
| { name: 'Spanish', value: 'Spanish' }, | ||
| { name: 'Thai', value: 'Thai' }, | ||
| { name: 'Turkish', value: 'Turkish' }, | ||
| { name: 'Vietnamese', value: 'Vietnamese' }, | ||
| ], | ||
| default: 'auto', | ||
| description: 'Enhance recognition for a specific language', | ||
| }, | ||
| { | ||
| displayName: 'Pitch', | ||
| name: 'pitch', | ||
| type: 'number', | ||
| typeOptions: { | ||
| minValue: -12, | ||
| maxValue: 12, | ||
| }, | ||
| default: 0, | ||
| description: 'Speech pitch adjustment (-12 to 12, 0 = original pitch)', | ||
| }, | ||
| { | ||
| displayName: 'Speed', | ||
| name: 'speed', | ||
| type: 'number', | ||
| typeOptions: { | ||
| minValue: 0.5, | ||
| maxValue: 2, | ||
| numberPrecision: 1, | ||
| }, | ||
| default: 1, | ||
| description: 'Speech speed (0.5-2, higher = faster)', | ||
| }, | ||
| { | ||
| displayName: 'Volume', | ||
| name: 'volume', | ||
| type: 'number', | ||
| typeOptions: { | ||
| minValue: 0.1, | ||
| maxValue: 10, | ||
| numberPrecision: 1, | ||
| }, | ||
| default: 1, | ||
| description: 'Speech volume (0.1-10, higher = louder)', | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| const displayOptions = { | ||
| show: { | ||
| resource: ['audio'], | ||
| operation: ['textToSpeech'], | ||
| }, | ||
| }; | ||
|
|
||
| export const description = updateDisplayOptions(displayOptions, properties); | ||
|
|
||
| export async function execute( | ||
| this: IExecuteFunctions, | ||
| itemIndex: number, | ||
| ): Promise<INodeExecutionData[]> { | ||
| const model = this.getNodeParameter('modelId', itemIndex) as string; | ||
| const text = this.getNodeParameter('text', itemIndex) as string; | ||
| const voiceId = this.getNodeParameter('voiceId', itemIndex) as string; | ||
| const downloadAudio = this.getNodeParameter('downloadAudio', itemIndex, true) as boolean; | ||
| const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject; | ||
|
|
||
| const audioFormat = (options.audioFormat as string) || 'mp3'; | ||
|
|
||
| const body: IDataObject = { | ||
| model, | ||
| text, | ||
| stream: false, | ||
| output_format: 'url', | ||
| voice_setting: { | ||
| voice_id: voiceId, | ||
| speed: (options.speed as number) ?? 1, | ||
| vol: (options.volume as number) ?? 1, | ||
| pitch: (options.pitch as number) ?? 0, | ||
| }, | ||
| audio_setting: { | ||
| format: audioFormat, | ||
| }, | ||
| }; | ||
|
|
||
| if (options.emotion) { | ||
| (body.voice_setting as IDataObject).emotion = options.emotion; | ||
| } | ||
|
|
||
| if (options.languageBoost) { | ||
| body.language_boost = options.languageBoost; | ||
| } | ||
|
|
||
| const response = (await apiRequest.call(this, 'POST', '/t2a_v2', { | ||
| body, | ||
| })) as T2AResponse; | ||
|
|
||
| if (response.base_resp?.status_code !== 0) { | ||
| throw new NodeOperationError( | ||
| this.getNode(), | ||
| `Text-to-speech failed: ${response.base_resp?.status_msg || 'Unknown error'}`, | ||
| ); | ||
| } | ||
|
|
||
| const audioData = response.data?.audio; | ||
| if (!audioData) { | ||
| throw new NodeOperationError(this.getNode(), 'No audio data returned'); | ||
| } | ||
|
|
||
| const jsonData: IDataObject = { | ||
| audioLength: response.extra_info?.audio_length, | ||
| audioFormat: response.extra_info?.audio_format, | ||
| audioSize: response.extra_info?.audio_size, | ||
| wordCount: response.extra_info?.word_count, | ||
| usageCharacters: response.extra_info?.usage_characters, | ||
| }; | ||
|
|
||
| if (downloadAudio) { | ||
| let binaryBuffer: Buffer; | ||
| let mimeType: string; | ||
|
|
||
| if (audioData.startsWith('http')) { | ||
| const audioResponse = await this.helpers.httpRequest({ | ||
| method: 'GET', | ||
| url: audioData, | ||
| encoding: 'arraybuffer', | ||
| returnFullResponse: true, | ||
| }); | ||
|
|
||
| mimeType = (audioResponse.headers?.['content-type'] as string) || `audio/${audioFormat}`; | ||
| binaryBuffer = Buffer.from(audioResponse.body as ArrayBuffer); | ||
| } else { | ||
| binaryBuffer = Buffer.from(audioData, 'hex'); | ||
| mimeType = `audio/${audioFormat}`; | ||
| } | ||
|
|
||
| const fileName = `speech.${audioFormat}`; | ||
| const binaryData = await this.helpers.prepareBinaryData(binaryBuffer, fileName, mimeType); | ||
|
|
||
| return [ | ||
| { | ||
| binary: { data: binaryData }, | ||
| json: jsonData, | ||
| pairedItem: { item: itemIndex }, | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| return [ | ||
| { | ||
| json: { ...jsonData, audioUrl: audioData }, | ||
| pairedItem: { item: itemIndex }, | ||
| }, | ||
| ]; | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of hardcoded
output_format: 'url',execution would always take this routeif (audioData.startsWith('http')) {- we should either add option or remove unused logicThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, removed the dead hex branch in 9e4d2dd.