-
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.
feat(streaming): add PlayDialog engine/model support (#43)
- Loading branch information
1 parent
dd0465b
commit 8018159
Showing
13 changed files
with
368 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test-output-*.mp3 |
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,92 @@ | ||
import { buffer } from 'node:stream/consumers'; | ||
import fs from 'node:fs'; | ||
import { describe, expect, it } from '@jest/globals'; | ||
import * as PlayHT from '../index'; | ||
import { E2E_CONFIG } from './e2eTestConfig'; | ||
|
||
describe('E2E Streaming', () => { | ||
describe('Play3.0-mini', () => { | ||
it('streams from text', async () => { | ||
PlayHT.init({ | ||
userId: E2E_CONFIG.USER_ID, | ||
apiKey: E2E_CONFIG.API_KEY, | ||
}); | ||
|
||
const streamFromText = await PlayHT.stream('Hello from SDK test.', { | ||
voiceEngine: 'Play3.0-mini', | ||
// @ts-expect-error emotion is not part of the Play3.0-mini contract | ||
emotion: 'female_surprised', | ||
outputFormat: 'mp3', | ||
}); | ||
|
||
const audioBuffer = await buffer(streamFromText); | ||
fs.writeFileSync('test-output-Play3.0-mini.mp3', audioBuffer); // for debugging | ||
|
||
expect(audioBuffer.length).toBeGreaterThan(30_000); // errors would result in smaller payloads | ||
expect(audioBuffer.toString('ascii')).toContain('ID3'); | ||
}); | ||
}); | ||
|
||
describe('PlayDialog', () => { | ||
it('streams from text', async () => { | ||
PlayHT.init({ | ||
userId: E2E_CONFIG.USER_ID, | ||
apiKey: E2E_CONFIG.API_KEY, | ||
}); | ||
|
||
const streamFromText = await PlayHT.stream('Host 1: Is this the SDK?\nHost 2: Yes, it is.', { | ||
voiceEngine: 'PlayDialog', | ||
outputFormat: 'mp3', | ||
temperature: 1.2, | ||
quality: 'high', | ||
voiceId2: 's3://voice-cloning-zero-shot/775ae416-49bb-4fb6-bd45-740f205d20a1/jennifersaad/manifest.json', | ||
turnPrefix: 'Host 1:', | ||
turnPrefix2: 'Host 2:', | ||
language: 'english', | ||
|
||
// @ts-expect-error emotion and language are not part of the PlayDialog contract | ||
emotion: 'female_surprised', | ||
styleGuidance: 16, | ||
}); | ||
|
||
const audioBuffer = await buffer(streamFromText); | ||
fs.writeFileSync('test-output-PlayDialog.mp3', audioBuffer); // for debugging | ||
|
||
expect(audioBuffer.length).toBeGreaterThan(30_000); // errors would result in smaller payloads | ||
expect(audioBuffer.toString('ascii')).toContain('ID3'); | ||
}, 120_000); | ||
}); | ||
|
||
describe('PlayDialogMultilingual', () => { | ||
it('streams from text', async () => { | ||
PlayHT.init({ | ||
userId: E2E_CONFIG.USER_ID, | ||
apiKey: E2E_CONFIG.API_KEY, | ||
}); | ||
|
||
const streamFromText = await PlayHT.stream( | ||
'Host 1: Estamos todos prontos para fazer o que for necessário aqui. Host 2: É impossível esquecer tudo que vivemos.', | ||
{ | ||
voiceEngine: 'PlayDialog', | ||
outputFormat: 'mp3', | ||
temperature: 1.2, | ||
quality: 'high', | ||
voiceId2: 's3://voice-cloning-zero-shot/775ae416-49bb-4fb6-bd45-740f205d20a1/jennifersaad/manifest.json', | ||
turnPrefix: 'Host 1:', | ||
turnPrefix2: 'Host 2:', | ||
language: 'portuguese', | ||
|
||
// @ts-expect-error emotion and language are not part of the PlayDialog contract | ||
emotion: 'female_surprised', | ||
styleGuidance: 16, | ||
}, | ||
); | ||
|
||
const audioBuffer = await buffer(streamFromText); | ||
fs.writeFileSync('test-output-PlayDialogMultilingual.mp3', audioBuffer); // for debugging | ||
|
||
expect(audioBuffer.length).toBeGreaterThan(30_000); // errors would result in smaller payloads | ||
expect(audioBuffer.toString('ascii')).toContain('ID3'); | ||
}, 120_000); | ||
}); | ||
}); |
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
16 changes: 15 additions & 1 deletion
16
packages/playht/src/api/internal/tts/v3/V3InternalSettings.ts
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
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
Oops, something went wrong.