{"id":16585,"date":"2025-07-09T01:15:53","date_gmt":"2025-07-08T23:15:53","guid":{"rendered":"https:\/\/www.beseit.net\/?p=16585"},"modified":"2025-07-09T09:48:18","modified_gmt":"2025-07-09T07:48:18","slug":"script-python-intelligent","status":"publish","type":"post","link":"http:\/\/www.beseit.net\/?p=16585","title":{"rendered":"script Python intel\u00b7ligent"},"content":{"rendered":"\n<p>Detecta si el text \u00e9s en <strong>catal\u00e0<\/strong> o <strong>angl\u00e8s<\/strong><\/p>\n\n\n\n<p>Tria autom\u00e0ticament la veu adequada per a <code>edge-tts<\/code><\/p>\n\n\n\n<p>Genera un fitxer <code>.mp3<\/code> amb veu natural<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tts_auto.py\nimport sys\nimport subprocess\nfrom langdetect import detect\n\n# ? Configura les veus segons l'idioma\nVOICES = {\n    'ca': 'ca-ES-JoanaNeural',\n    'en': 'en-GB-LibbyNeural'\n}\n\ndef detect_language(text):\n    try:\n        lang = detect(text)\n        return lang if lang in VOICES else 'en'\n    except:\n        return 'en'\n\ndef synthesize(text, output_file):\n    lang = detect_language(text)\n    voice = VOICES&#91;lang]\n    print(f\"Idioma detectat: {lang} \u2192 Veu: {voice}\")\n    \n    command = &#91;\n        '\/var\/services\/homes\/urqtejmi\/.local\/bin\/edge-tts',\n        '--text', text,\n        '--voice', voice,\n        '--write-media', output_file\n    ]\n    \n    subprocess.run(command)\n\nif __name__ == \"__main__\":\n    if len(sys.argv) &lt; 2:\n        print(\"\u00das: python tts_auto.py \\\"Text a llegir\\\"\")\n        sys.exit(1)\n\n    text = sys.argv&#91;1]\n    output = \"sortida.mp3\"\n    synthesize(text, output)\n    print(f\"\u00c0udio generat: {output}\")\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Detecta si el text \u00e9s en catal\u00e0 o angl\u00e8s Tria autom\u00e0ticament la veu adequada per a edge-tts Genera un fitxer .mp3 amb veu natural<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-16585","post","type-post","status-publish","format-standard","hentry","category-bloc-de-notes"],"_links":{"self":[{"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/posts\/16585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.beseit.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16585"}],"version-history":[{"count":1,"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/posts\/16585\/revisions"}],"predecessor-version":[{"id":16586,"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/posts\/16585\/revisions\/16586"}],"wp:attachment":[{"href":"http:\/\/www.beseit.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.beseit.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16585"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.beseit.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}