add twurple-compatible polly class

This commit is contained in:
2025-01-27 14:42:33 +00:00
parent 07c0091bab
commit f6da74d4d1
3 changed files with 351 additions and 1 deletions
+47 -1
View File
@@ -187,4 +187,50 @@ export function SynthesizeSpeech(
return fetch(url,{headers:auth_headers})
}
export default SynthesizeSpeech
export default SynthesizeSpeech
export class Polly {
/** @type {import('@twurple/auth').AuthProvider} */
#auth_provider = null;
/**
*
* @param {import('@twurple/auth').AuthProvider} auth_provider
*/
constructor(auth_provider) {
this.#auth_provider = auth_provider
}
async #GetAuthHeaders() {
const token = await this.#auth_provider.getAccessTokenForUser()
return {
'authorization': 'OAuth ' + token.access_token,
'client-id': this.#auth_provider.client_id
}
}
DescribeVoices(Engine = 'standard', LanguageCode = '', IncludeAdditionalLanguageCodes = true) {
return DescribeVoices(this.#GetAuthHeaders(), Engine, LanguageCode, IncludeAdditionalLanguageCodes)
}
SynthesizeSpeech(
Text,
VoiceId,
TextType = 'text',
Engine = 'standard',
LanguageCode = '',
OutputFormat = 'mp3',
SampleRate = '24000') {
return SynthesizeSpeech(
this.#GetAuthHeaders(),
Text,
VoiceId,
TextType,
Engine,
LanguageCode,
OutputFormat,
SampleRate
)
}
}