Skip to content

Commit 849faac

Browse files
committed
added ChaptGPT (selfhosted) option with the objective of use custom hosted voices
1 parent fd2595d commit 849faac

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

css/options.css

+16
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ input[type=checkbox], input[type=radio] {
234234
margin-top: 1.5em;
235235
}
236236

237+
#voice-custom-input-div {
238+
display: none;
239+
}
240+
241+
div.inline-div { display: table; }
242+
div.inline-input {
243+
display: table-cell;
244+
width: 100%;
245+
margin: 1px;
246+
}
247+
#voice-custom-input {
248+
display: table-cell;
249+
width: 100%;
250+
margin: 1px;
251+
}
252+
237253
#rate-input-div {
238254
display: none;
239255
}

js/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function parseUrl(url) {
266266
*/
267267
function getSettings(names) {
268268
return new Promise(function(fulfill) {
269-
brapi.storage.local.get(names || ["voiceName", "rate", "pitch", "volume", "showHighlighting", "languages", "highlightFontSize", "highlightWindowSize", "preferredVoices"], fulfill);
269+
brapi.storage.local.get(names || ["voiceName", "voiceCustom", "rate", "pitch", "volume", "showHighlighting", "languages", "highlightFontSize", "highlightWindowSize", "preferredVoices"], fulfill);
270270
});
271271
}
272272

@@ -278,7 +278,7 @@ function updateSettings(items) {
278278

279279
function clearSettings(names) {
280280
return new Promise(function(fulfill) {
281-
brapi.storage.local.remove(names || ["voiceName", "rate", "pitch", "volume", "showHighlighting", "languages", "highlightFontSize", "highlightWindowSize", "preferredVoices"], fulfill);
281+
brapi.storage.local.remove(names || ["voiceName", "voiceCustom", "rate", "pitch", "volume", "showHighlighting", "languages", "highlightFontSize", "highlightWindowSize", "preferredVoices"], fulfill);
282282
});
283283
}
284284

js/options.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,31 @@ function initialize(allVoices, settings) {
6262
.val(settings.voiceName || "")
6363
.change(function() {
6464
var voiceName = $(this).val();
65-
if (voiceName == "@custom") location.href = "custom-voices.html";
66-
else if (voiceName == "@premium") brapi.tabs.create({url: "premium-voices.html"});
67-
else if (voiceName == "@piper") bgPageInvoke("managePiperVoices")
68-
else saveSettings({voiceName: voiceName});
65+
if (voiceName == "ChatGPT English (selfhosted)") {
66+
$("#voice-custom-input-div").show();
67+
saveSettings({voiceName: voiceName});
68+
} else {
69+
$("#voice-custom-input-div").hide();
70+
if (voiceName == "@custom") location.href = "custom-voices.html";
71+
else if (voiceName == "@premium") brapi.tabs.create({url: "premium-voices.html"});
72+
else if (voiceName == "@piper") bgPageInvoke("managePiperVoices")
73+
else saveSettings({voiceName: voiceName});
74+
}
6975
});
7076
$("#languages-edit-button").click(function() {
7177
location.href = "languages.html";
7278
})
7379

80+
//voice custom input
81+
if(settings.voiceName == "ChatGPT English (selfhosted)") $("#voice-custom-input-div").show();
82+
$("#voice-custom-input").val(settings.voiceCustom || "");
83+
84+
//voice custom save button
85+
$("#save-custom-voice").click(function() {
86+
var voiceCustom = $("#voice-custom-input").val().trim();
87+
saveSettings({voiceCustom: voiceCustom});
88+
showConfirmation();
89+
});
7490

7591
//rate input
7692
$("#rate-edit-button").click(function() {

js/tts-engines.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ function OpenaiTtsEngine() {
14721472
async function getAudioUrl(text, voice, pitch) {
14731473
assert(text && voice)
14741474
const matches = voice.voiceName.match(/^ChatGPT .* \((\w+)\)$/)
1475-
const voiceName = matches[1]
1475+
const voiceName = matches[1] != "selfhosted" ? matches[1] : (await getSettings(["voiceCustom"])).voiceCustom;
14761476
const {openaiCreds} = await getSettings(["openaiCreds"])
14771477
const res = await fetch((openaiCreds.url || defaultApiUrl) + "/audio/speech", {
14781478
method: "POST",
@@ -1497,6 +1497,7 @@ function OpenaiTtsEngine() {
14971497
{"voiceName":"ChatGPT English (onyx)","lang":"en-US","gender":"male"},
14981498
{"voiceName":"ChatGPT English (nova)","lang":"en-US","gender":"female"},
14991499
{"voiceName":"ChatGPT English (shimmer)","lang":"en-US","gender":"female"},
1500+
{"voiceName":"ChatGPT English (selfhosted)","lang":"en-US","gender":"male"},
15001501
]
15011502
}
15021503

options.html

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ <h2 data-i18n="options_heading"></h2>
4949
Note: This voice may become unavailable at any time.
5050
<a href='http://blog.readaloud.app/2018/10/the-state-of-text-to-speech-technology.html' target='_blank'>Read more</a> about it on our blog.
5151
</small>
52+
<div id="voice-custom-input-div">
53+
<div class="inline-div">
54+
<div class="inline-input"><input placeholder="Custom voice name" id="voice-custom-input" class="form-control" type="text" /></div>
55+
<button type="button" id="save-custom-voice" class="btn btn-info">
56+
<span data-i18n="options_save_button"></span>
57+
</button>
58+
</div>
59+
</div>
5260
</div>
5361

5462
<div>

0 commit comments

Comments
 (0)