Back to Home
Gistify Snippet
Public
Scraper edge-tts
Scraper edge-tts
#github-gist#javascript#gist:a7933a15216a98fa742015bc8c83ab5f#gistsync:2026-09-02T12:40:26Z
0
Rawedge-tts.jsjavascript
82 lines| 1 | |
| 2 | |
| 3 | import * as __ns_101 from 'node-edge-tts' |
| 4 | const EdgeTTS = __ns_101.EdgeTTS |
| 5 | import * as __ns_102 from 'node:crypto' |
| 6 | const crypto = __ns_102.default |
| 7 | import * as __ns_103 from 'node:fs/promises' |
| 8 | const fs = __ns_103.default |
| 9 | import * as __ns_104 from 'node:os' |
| 10 | const os = __ns_104.default |
| 11 | import * as __ns_105 from 'node:path' |
| 12 | const path = __ns_105.default |
| 13 | import * as __ns_106 from 'node:url' |
| 14 | const pathToFileURL = __ns_106.pathToFileURL |
| 15 | |
| 16 | async function edgeTTS(text, voice = "id-ID-ArdiNeural", lang = "id-ID") { |
| 17 | if (!text || typeof text !== 'string') throw new Error("Text must be a non-empty string"); |
| 18 | const sanitizedText = text.trim().substring(0, 3000); // 3k char limit for stability |
| 19 | |
| 20 | const outputDir = path.join(os.tmpdir(), "tts"); |
| 21 | const fileName = `edge-${crypto.randomUUID()}.mp3`; |
| 22 | const outputPath = path.join(outputDir, fileName); |
| 23 | |
| 24 | try { |
| 25 | await fs.mkdir(outputDir, { recursive: true }); |
| 26 | const edge = new EdgeTTS({ voice, lang }); |
| 27 | await edge.ttsPromise(sanitizedText, outputPath); |
| 28 | const buffer = await fs.readFile(outputPath); |
| 29 | await fs.unlink(outputPath).catch(() => {}); |
| 30 | return { |
| 31 | status: true, |
| 32 | result: buffer |
| 33 | }; |
| 34 | } catch (error) { |
| 35 | return { |
| 36 | status: false, |
| 37 | message: error.message |
| 38 | }; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { |
| 43 | const __exports = { edgeTTS: edgeTTS } |
| 44 | const __fns = Object.fromEntries(Object.entries(__exports).filter(([, v]) => typeof v === 'function')) |
| 45 | const __names = Object.keys(__fns) |
| 46 | if (__names.length === 0) { |
| 47 | console.log('Tidak ada fungsi yang bisa di-demo. Import modul ini dari kode lain.') |
| 48 | } else { |
| 49 | const __search = __names.find((n) => /search|cari/i.test(n)) |
| 50 | const __name = __search || __names[0] |
| 51 | const __fn = __fns[__name] |
| 52 | const __isClass = /^class\s/.test(Function.prototype.toString.call(__fn)) |
| 53 | const __defaultArgs = (() => { |
| 54 | const n = __name.toLowerCase() |
| 55 | if (/emoji/.test(n)) return [{ emoji: '๐๐' }] |
| 56 | if (/textpro|generate.*text|effect/.test(n)) return ['neon', 'Hello'] |
| 57 | if (/image|wallpaper|search|query|anime|movie|manga|news|lyrics|wiki|quote|stalk|detail/.test(n)) return ['naruto'] |
| 58 | if (/download|youtube|video|audio|music|spotify|tiktok|instagram|facebook|twitter|reels|terabox|media/.test(n)) return ['https://www.youtube.com/watch?v=dQw4w9WgXcQ'] |
| 59 | if (/dork/.test(n)) return ['example.com', 'documents'] |
| 60 | if (/tts|speech|prompt|chat|ask|translate/.test(n)) return ['Hello world'] |
| 61 | if (/parse|format|normalize|list|features/.test(n)) return [] |
| 62 | return ['test'] |
| 63 | })() |
| 64 | let __args = __defaultArgs |
| 65 | if (process.argv.length > 2) __args = process.argv.slice(2).map((a) => { try { return JSON.parse(a) } catch { return a } }) |
| 66 | if (__args.length === 0 && !__search && !__isClass && __fn.length > 0) { |
| 67 | console.log('Fungsi: ' + __names.join(', ')) |
| 68 | console.log('Contoh: node ' + "edge-tts.js" + ' ' + __name + ' <arg>') |
| 69 | } else { |
| 70 | ;(async () => { |
| 71 | try { |
| 72 | const r = __isClass ? new __fn(...__args) : await __fn(...__args) |
| 73 | console.log(JSON.stringify(r, null, 2)) |
| 74 | } catch (e) { |
| 75 | console.error('Error: ' + (e && e.message ? e.message : e)) |
| 76 | process.exitCode = 1 |
| 77 | } |
| 78 | })() |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
Discussion & Comments0
No comments yet โ be the first to leave feedback or start a code discussion.
Sign in with your GitHub account to write comments and join the discussion.