-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
0 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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
margin: 2em; | ||
} | ||
</style> | ||
<!-- <script src=" https://cdn.jsdelivr.net/npm/[email protected]/lame.min.js"></script> --> | ||
</head> | ||
<body> | ||
<h1>llama.cpp TTS</h1> | ||
|
@@ -20,11 +21,13 @@ <h1>llama.cpp TTS</h1> | |
<br/> | ||
<p id="status">Status: ready</p><br/> | ||
<p id="output"></p> | ||
<a id="download"></a> | ||
|
||
<script> | ||
const input_el = document.getElementById('input'); | ||
const output_el = document.getElementById('output'); | ||
const status_el = document.getElementById('status'); | ||
const download_el = document.getElementById('download'); | ||
const btn_speak_el = document.getElementById('btn_speak'); | ||
|
||
let working = false; | ||
|
@@ -38,6 +41,7 @@ <h1>llama.cpp TTS</h1> | |
input_el.disabled = true; | ||
btn_speak_el.disabled = true; | ||
status_el.textContent = 'Status: generating...'; | ||
download_el.textContent = ''; | ||
|
||
const input = input_el.value.trim(); | ||
|
||
|
@@ -56,13 +60,19 @@ <h1>llama.cpp TTS</h1> | |
if (res.status === 200) { | ||
const blob = await res.blob(); | ||
const url = URL.createObjectURL(blob); | ||
download_el.href = url; | ||
download_el.innerText = 'Download'; | ||
download_el.download = getFileNameWAV(input); | ||
const audio = new Audio(url); | ||
audio.play(); | ||
status_el.textContent = 'Status: playing...'; | ||
audio.addEventListener('ended', () => { | ||
status_el.textContent = 'Status: ready'; | ||
}); | ||
echoTimings(res.headers, input); | ||
|
||
// const buffer = await blob.arrayBuffer(); | ||
// wavToMp3(new Int16Array(buffer)); | ||
} else { | ||
const text = await res.text(); | ||
throw new Error(`Failed to generate speech: ${text}`); | ||
|
@@ -107,6 +117,14 @@ <h1>llama.cpp TTS</h1> | |
.replace(/"/g, """) | ||
.replace(/'/g, "'"); | ||
} | ||
|
||
function getFileNameWAV(input) { | ||
return input.replace(/[^a-z0-9]/gi, '_').toLowerCase().substring(0, 32) + '.wav'; | ||
} | ||
|
||
function wavToMp3(wavData) { | ||
// TODO: implement this using lamejs | ||
} | ||
</script> | ||
</body> | ||
</html> |