diff src/site.js @ 12:2d4b3f003ec2

tts
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 24 Jul 2025 22:14:49 -0600
parents 46097e607701
children f5425a3c1898
line wrap: on
line diff
--- a/src/site.js	Tue Jul 22 15:30:10 2025 -0600
+++ b/src/site.js	Thu Jul 24 22:14:49 2025 -0600
@@ -119,7 +119,11 @@
 	window.scrollTo( 0, lastY );
 }
 
+
 // requires markdown-it
+
+let mdDiv = document.createElement('div');
+
 function handleMarkdown() {
 	let converter = window.markdownit({html: true});
 	let divs = document.querySelectorAll('[markdown]');
@@ -127,6 +131,15 @@
 		let text = div.textContent;
 		text = text.replace(/\{([^|}]+)\|([^|}]+)\}/g, '<ruby>$1<rt>$2</rt></ruby>');
 		text = converter.render(text);
+		if( div.getAttribute('role')==='assistant' ) {
+			mdDiv.innerHTML = text;
+			let rts = mdDiv.querySelectorAll('rt');
+			for( let rt of rts ) {
+				rt.remove();
+			}
+			//console.log(mdDiv.textContent);
+			text += `\n<p><audio controls preload=none src="/tts.mp3?text=${encodeURIComponent(mdDiv.textContent)}"></p>\n`;
+		}
 		div.innerHTML = text;
 		div.removeAttribute('markdown');
 	}