community_icon_html = """""" loading_icon_html = """""" share_js = """async () => { async function uploadFile(file){ const UPLOAD_URL = 'https://huggingface.co/uploads'; const response = await fetch(UPLOAD_URL, { method: 'POST', headers: { 'Content-Type': file.type, 'X-Requested-With': 'XMLHttpRequest', }, body: file, /// <- File inherits from Blob }); const url = await response.text(); return url; } async function getInputAudioFile(audioEl){ const res = await fetch(audioEl.src); const blob = await res.blob(); const audioId = Date.now(); const fileName = `bark-audio-${{audioId}}.wav`; return new File([blob], fileName, { type: 'audio/wav' }); } async function audioToBase64(audioFile) { return new Promise((resolve, reject) => { let reader = new FileReader(); reader.readAsDataURL(audioFile); reader.onload = () => resolve(reader.result); reader.onerror = error => reject(error); }); } const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app'); const inputText = gradioEl.querySelector('#input_text textarea').value; const speakerOption = gradioEl.querySelector('#speaker_option .single-select').innerText; const audioElement = gradioEl.querySelector('#audio_out audio'); const titleTxt = `Bark: ${inputText.slice(0, 50)}...`; const shareBtnEl = gradioEl.querySelector('#share-btn'); const shareIconEl = gradioEl.querySelector('#share-btn-share-icon'); const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon'); if(!audioElement){ return; }; shareBtnEl.style.pointerEvents = 'none'; shareIconEl.style.display = 'none'; loadingIconEl.style.removeProperty('display'); const outputAudioFile = await getInputAudioFile(audioElement); const urlOutputAudio = await uploadFile(outputAudioFile); const descriptionMd = ` ### Text ${inputText} ### Acoustic Prompt ${speakerOption} ### Audio `; const params = new URLSearchParams({ title: titleTxt, description: descriptionMd, }); const paramsStr = params.toString(); window.open(`https://huggingface.co/spaces/suno/bark/discussions/new?${paramsStr}`, '_blank'); shareBtnEl.style.removeProperty('pointer-events'); shareIconEl.style.removeProperty('display'); loadingIconEl.style.display = 'none'; }"""