Blame Raw Code Preview
· · · 81 lines (3.5 KB)
0 contributors
1# Provider Requirements.
2Because I don't know how, or if you can, and/or maybe I am just too lazy to implement interfaces in JS, here's the requirements of a provider that the extension needs to operate.
3
4### class YourTtsProvider
5#### Required
6Exported for use in extension index.js, and added to providers list in index.js
71. generateTts(text, voiceId)
82. fetchTtsVoiceObjects()
93. onRefreshClick()
104. checkReady()
115. loadSettings(settingsObject)
126. settings field
137. settingsHtml field
14
15#### Optional
161. previewTtsVoice()
172. separator field
183. processText(text)
194. dispose()
20
21# Requirement Descriptions
22### generateTts(text, voiceId)
23Must return `audioData.type in ['audio/mpeg', 'audio/wav', 'audio/x-wav', 'audio/wave', 'audio/webm']`
24Must take text to be rendered and the voiceId to identify the voice to be used
25
26### fetchTtsVoiceObjects()
27Required.
28Used by the TTS extension to get a list of voice objects from the provider.
29Must return an list of voice objects representing the available voices.
301. name: a friendly user facing name to assign to characters. Shows in dropdown list next to user.
312. voice_id: the provider specific id of the voice used in fetchTtsGeneration() call
323. preview_url: a URL to a local audio file that will be used to sample voices
334. lang: OPTIONAL language string
34
35### getVoice(voiceName)
36Required.
37Must return a single voice object matching the provided voiceName. The voice object must have the following at least:
381. name: a friendly user facing name to assign to characters. Shows in dropdown list next to user.
392. voice_id: the provider specific id of the voice used in fetchTtsGeneration() call
403. preview_url: a URL to a local audio file that will be used to sample voices
414. lang: OPTIONAL language indicator
42
43### onRefreshClick()
44Required.
45Users click this button to reconnect/reinit the selected provider.
46Responds to the user clicking the refresh button, which is intended to re-initialize the Provider into a working state, like retrying connections or checking if everything is loaded.
47
48### checkReady()
49Required.
50Return without error to let TTS extension know that the provider is ready.
51Return an error to block the main TTS extension for initializing the provider and UI. The error will be put in the TTS extension UI directly.
52
53### loadSettings(settingsObject)
54Required.
55Handle the input settings from the TTS extension on provider load.
56Put code in here to load your provider settings.
57
58### settings field
59Required, used for storing any provider state that needs to be saved.
60Anything stored in this field is automatically persisted under extension_settings[providerName] by the main extension in `saveTtsProviderSettings()`, as well as loaded when the provider is selected in `loadTtsProvider(provider)`.
61TTS extension doesn't expect any specific contents.
62
63### settingsHtml field
64Required, injected into the TTS extension UI. Besides adding it, not relied on by TTS extension directly.
65
66### previewTtsVoice()
67Optional.
68Function to handle playing previews of voice samples if no direct preview_url is available in fetchTtsVoiceObjects() response
69
70### separator field
71Optional.
72Used when narrate quoted text is enabled.
73Defines the string of characters used to introduce separation between between the groups of extracted quoted text sent to the provider. The provider will use this to introduce pauses by default using `...`
74
75### processText(text)
76Optional.
77A function applied to the input text before passing it to the TTS generator. Can be async.
78
79### dispose()
80Optional.
81Function to handle cleanup of provider resources when the provider is switched.