Back to Home
Gistify Snippet
kyiov
Sep 4ยท1 file(s)
Public

Scraper google-tts

Scraper google-tts

#github-gist#javascript#gist:02baa1f9459358101cb3ca7599db47af#gistsync:2026-09-02T12:40:27Z
0
Raw
google-tts.jsjavascript
70 lines
1
2
3import * as __ns_137 from 'google-tts-api'
4const googleTTS = __ns_137.default
5import * as __ns_138 from 'node:url'
6const pathToFileURL = __ns_138.pathToFileURL
7
8async function googleTextToSpeech(text, lang = "id") {
9 if (!text || typeof text !== 'string') throw new Error("Text must be a non-empty string");
10 const sanitizedText = text.trim().substring(0, 1000); // Google TTS has shorter limits
11
12 try {
13 const url = googleTTS.getAudioUrl(sanitizedText, {
14 lang,
15 slow: false,
16 host: 'https://translate.google.com'
17 });
18 return {
19 status: true,
20 result: url
21 };
22 } catch (error) {
23 return {
24 status: false,
25 message: error.message
26 };
27 }
28}
29
30if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
31 const __exports = { googleTextToSpeech: googleTextToSpeech }
32 const __fns = Object.fromEntries(Object.entries(__exports).filter(([, v]) => typeof v === 'function'))
33 const __names = Object.keys(__fns)
34 if (__names.length === 0) {
35 console.log('Tidak ada fungsi yang bisa di-demo. Import modul ini dari kode lain.')
36 } else {
37 const __search = __names.find((n) => /search|cari/i.test(n))
38 const __name = __search || __names[0]
39 const __fn = __fns[__name]
40 const __isClass = /^class\s/.test(Function.prototype.toString.call(__fn))
41 const __defaultArgs = (() => {
42 const n = __name.toLowerCase()
43 if (/emoji/.test(n)) return [{ emoji: '๐Ÿ˜€๐Ÿ˜ƒ' }]
44 if (/textpro|generate.*text|effect/.test(n)) return ['neon', 'Hello']
45 if (/image|wallpaper|search|query|anime|movie|manga|news|lyrics|wiki|quote|stalk|detail/.test(n)) return ['naruto']
46 if (/download|youtube|video|audio|music|spotify|tiktok|instagram|facebook|twitter|reels|terabox|media/.test(n)) return ['https://www.youtube.com/watch?v=dQw4w9WgXcQ']
47 if (/dork/.test(n)) return ['example.com', 'documents']
48 if (/tts|speech|prompt|chat|ask|translate/.test(n)) return ['Hello world']
49 if (/parse|format|normalize|list|features/.test(n)) return []
50 return ['test']
51 })()
52 let __args = __defaultArgs
53 if (process.argv.length > 2) __args = process.argv.slice(2).map((a) => { try { return JSON.parse(a) } catch { return a } })
54 if (__args.length === 0 && !__search && !__isClass && __fn.length > 0) {
55 console.log('Fungsi: ' + __names.join(', '))
56 console.log('Contoh: node ' + "google-tts.js" + ' ' + __name + ' <arg>')
57 } else {
58 ;(async () => {
59 try {
60 const r = __isClass ? new __fn(...__args) : await __fn(...__args)
61 console.log(JSON.stringify(r, null, 2))
62 } catch (e) {
63 console.error('Error: ' + (e && e.message ? e.message : e))
64 process.exitCode = 1
65 }
66 })()
67 }
68 }
69}
70
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.