Spaces:
Paused
Paused
Update main.ts
Browse files
main.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import { serve } from "https://deno.land/std/http/server.ts";
|
| 2 |
import { EdgeSpeechTTS } from "https://esm.sh/@lobehub/tts@1";
|
| 3 |
|
| 4 |
-
|
| 5 |
const VOICES_URL = "https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=6A5AA1D4EAFF4E9FB37E23D68491D6F4";
|
| 6 |
|
| 7 |
async function fetchVoiceList() {
|
|
@@ -25,17 +25,38 @@ async function synthesizeSpeech(model: string, voice: string, text: string) {
|
|
| 25 |
pitch = 0.2;
|
| 26 |
|
| 27 |
switch (voice) {
|
| 28 |
-
case "
|
| 29 |
-
voiceName = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
break;
|
| 31 |
-
case "
|
| 32 |
-
voiceName = "
|
| 33 |
break;
|
| 34 |
-
case "
|
| 35 |
-
voiceName = "
|
| 36 |
break;
|
| 37 |
default:
|
| 38 |
-
voiceName = "
|
| 39 |
break;
|
| 40 |
}
|
| 41 |
} else {
|
|
@@ -412,9 +433,9 @@ async function handleDemoRequest(req: Request) {
|
|
| 412 |
<h1>голос</h1>
|
| 413 |
<div id="voices"></div>
|
| 414 |
</div>
|
| 415 |
-
</div>
|
| 416 |
-
|
| 417 |
-
|
| 418 |
|
| 419 |
return new Response(html, {
|
| 420 |
headers: { "Content-Type": "text/html" },
|
|
|
|
| 1 |
import { serve } from "https://deno.land/std/http/server.ts";
|
| 2 |
import { EdgeSpeechTTS } from "https://esm.sh/@lobehub/tts@1";
|
| 3 |
|
| 4 |
+
|
| 5 |
const VOICES_URL = "https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=6A5AA1D4EAFF4E9FB37E23D68491D6F4";
|
| 6 |
|
| 7 |
async function fetchVoiceList() {
|
|
|
|
| 25 |
pitch = 0.2;
|
| 26 |
|
| 27 |
switch (voice) {
|
| 28 |
+
case "ava":
|
| 29 |
+
voiceName = "en-US-AvaMultilingualNeural";
|
| 30 |
+
break;
|
| 31 |
+
case "andrew":
|
| 32 |
+
voiceName = "en-US-AndrewMultilingualNeural";
|
| 33 |
+
break;
|
| 34 |
+
case "emma":
|
| 35 |
+
voiceName = "en-US-EmmaMultilingualNeural";
|
| 36 |
+
break;
|
| 37 |
+
case "brian":
|
| 38 |
+
voiceName = "en-US-BrianMultilingualNeural";
|
| 39 |
+
break;
|
| 40 |
+
case "vivienne":
|
| 41 |
+
voiceName = "fr-FR-VivienneMultilingualNeural";
|
| 42 |
+
break;
|
| 43 |
+
case "remy":
|
| 44 |
+
voiceName = "fr-FR-RemyMultilingualNeural";
|
| 45 |
+
break;
|
| 46 |
+
case "seraphina":
|
| 47 |
+
voiceName = "de-DE-SeraphinaMultilingualNeural";
|
| 48 |
+
break;
|
| 49 |
+
case "florian":
|
| 50 |
+
voiceName = "de-DE-FlorianMultilingualNeural";
|
| 51 |
break;
|
| 52 |
+
case "dmitry":
|
| 53 |
+
voiceName = "ru-RU-DmitryNeural";
|
| 54 |
break;
|
| 55 |
+
case "svetlana":
|
| 56 |
+
voiceName = "ru-RU-SvetlanaNeural";
|
| 57 |
break;
|
| 58 |
default:
|
| 59 |
+
voiceName = "en-US-BrianMultilingualNeural";
|
| 60 |
break;
|
| 61 |
}
|
| 62 |
} else {
|
|
|
|
| 433 |
<h1>голос</h1>
|
| 434 |
<div id="voices"></div>
|
| 435 |
</div>
|
| 436 |
+
</div>
|
| 437 |
+
<script>const voiceList = ${JSON.stringify(groupedVoiceList)};let audio=null;function filterVoices(){const keywords=document.getElementById('keywords').value.split(',').map(k=>k.trim().toLowerCase());const voicesDiv=document.getElementById('voices');voicesDiv.innerHTML='';const filteredVoices={};for(const[locale,voices]of Object.entries(voiceList)){const filtered=voices.filter(({name,friendlyName})=>keywords.some(keyword=>name.toLowerCase().includes(keyword)||friendlyName.toLowerCase().includes(keyword)));if(filtered.length>0){filteredVoices[locale]=filtered}}for(const[locale,voices]of Object.entries(filteredVoices)){const group=document.createElement('div');group.className='voice-group';group.draggable=true;const header=document.createElement('div');header.className='voice-header';header.textContent=locale.toUpperCase();const chevron=document.createElement('span');chevron.className='chevron';chevron.innerHTML='▼';header.appendChild(chevron);const buttonsContainer=document.createElement('div');buttonsContainer.className='voice-buttons';voices.forEach(({model,name})=>{const button=document.createElement('button');button.className='voice-button';button.textContent=name;button.onclick=()=>synthesize(model);buttonsContainer.appendChild(button)});header.onclick=()=>{group.classList.toggle('open')};group.appendChild(header);group.appendChild(buttonsContainer);voicesDiv.appendChild(group)}addDragDropListeners()}function synthesize(model){const text=document.getElementById('inputText').value||'Hello world';const rate=document.getElementById('rate').value||'-0.1';const pitch=document.getElementById('pitch').value||'0.1';const voice=\`rate:\${rate}|pitch:\${pitch}\`;if(audio){audio.pause();audio.currentTime=0}fetch('/v1/audio/speech',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({model,input:text,voice})}).then(response=>response.blob()).then(blob=>{const audioUrl=URL.createObjectURL(blob);audio=new Audio(audioUrl);audio.play()})}function addDragDropListeners(){const voicesDiv=document.getElementById('voices');let draggedItem=null;voicesDiv.addEventListener('dragstart',e=>{draggedItem=e.target;e.target.classList.add('dragging')});voicesDiv.addEventListener('dragend',e=>{e.target.classList.remove('dragging');draggedItem=null});voicesDiv.addEventListener('dragover',e=>{e.preventDefault();const afterElement=getDragAfterElement(voicesDiv,e.clientY);if(afterElement==null){voicesDiv.appendChild(draggedItem)}else{voicesDiv.insertBefore(draggedItem,afterElement)}})}function getDragAfterElement(container,y){const draggableElements=[...container.querySelectorAll('.voice-group:not(.dragging)')];return draggableElements.reduce((closest,child)=>{const box=child.getBoundingClientRect();const offset=y-box.top-box.height/2;if(offset<0&&offset>closest.offset){return{offset:offset,element:child}}else{return closest}},{offset:Number.NEGATIVE_INFINITY}).element}filterVoices();document.getElementById('keywords').addEventListener('input',filterVoices);const rateSlider=document.getElementById('rate');const rateValue=document.getElementById('rateValue');rateSlider.oninput=function(){rateValue.innerHTML=this.value};const pitchSlider=document.getElementById('pitch');const pitchValue=document.getElementById('pitchValue');pitchSlider.oninput=function(){pitchValue.innerHTML=this.value}</script>
|
| 438 |
+
</body></html>`;
|
| 439 |
|
| 440 |
return new Response(html, {
|
| 441 |
headers: { "Content-Type": "text/html" },
|