Skip to content

Commit 1078827

Browse files
committedApr 10, 2025·
V 3.1.3 Alpha
- Update "main.py" - Add installazione di Python 3.10 necessario per alcuni script - Update "transcribe_wav.py" - Fix adesso lo script viene eseguito con la corretta versione di python in maniera automatica
1 parent 3461587 commit 1078827

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed
 

‎main.py

+43
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,43 @@
33
import sys
44
import subprocess
55

6+
def install_python_3_10():
7+
"""
8+
Verifica se Python 3.10 è installato e, se non lo è, lo installa tramite winget.
9+
"""
10+
try:
11+
# Verifica se Python 3.10 è già installato
12+
result = subprocess.run(["python3.10", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
13+
if result.returncode != 0:
14+
print("Python 3.10 non trovato. Installazione in corso...")
15+
subprocess.run(["winget", "install", "Python.Python.3.10"], check=True)
16+
print("Python 3.10 installato con successo.")
17+
else:
18+
print("Python 3.10 già installato.")
19+
except FileNotFoundError:
20+
print("Python 3.10 non trovato. Installazione in corso...")
21+
subprocess.run(["winget", "install", "Python.Python.3.10"], check=True)
22+
print("Python 3.10 installato con successo.")
23+
except subprocess.CalledProcessError as e:
24+
print(f"Errore durante l'installazione di Python 3.10: {e}")
25+
26+
def install_requirements():
27+
"""
28+
Installa le dipendenze presenti nel file requirements.txt.
29+
Se il file non esiste, stampa un messaggio di avviso.
30+
"""
31+
requirements_file = 'requirements.txt'
32+
33+
if os.path.isfile(requirements_file):
34+
print("Trovato requirements.txt. Installazione delle dipendenze...")
35+
try:
36+
subprocess.run([sys.executable, "-m", "pip", "install", "-r", requirements_file], check=True)
37+
print("Dipendenze installate con successo.")
38+
except subprocess.CalledProcessError as e:
39+
print(f"Errore durante l'installazione delle dipendenze: {e}")
40+
else:
41+
print("requirements.txt non trovato. Nessuna dipendenza da installare.")
42+
643
def get_scripts(directory):
744
"""
845
Restituisce una lista di file .py presenti in 'directory',
@@ -51,6 +88,12 @@ def get_description(filepath):
5188
return "Nessuna descrizione disponibile."
5289

5390
def main():
91+
# Installa Python 3.10 se non è già installato
92+
install_python_3_10()
93+
94+
# Installa le dipendenze da requirements.txt (se presente)
95+
install_requirements()
96+
5497
# Se esiste una cartella "scripts", usiamola, altrimenti la directory corrente
5598
base_dir = os.getcwd()
5699
scripts_dir = os.path.join(base_dir, "scripts")

‎scripts/transcribe_wav.py

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
# Conversione audio .wav in testo con Whisper di OpenAI e salvataggio in .txt.
2+
#!/usr/bin/env python3
23
import os
3-
import whisper
4-
from pydub import AudioSegment
4+
import subprocess
5+
import sys
6+
7+
def ensure_python_3_10():
8+
"""
9+
Verifica se Python 3.10 è in uso, altrimenti forza l'esecuzione con Python 3.10.
10+
"""
11+
if sys.version_info[0] != 3 or sys.version_info[1] != 10:
12+
print("Forzando l'esecuzione con Python 3.10...")
13+
14+
# Aggiungi temporaneamente il percorso di Python 3.10 alla variabile d'ambiente PATH
15+
python_path = r"C:\Users\utente\AppData\Local\Programs\Python\Python310"
16+
if python_path not in os.environ["PATH"]:
17+
os.environ["PATH"] += os.pathsep + python_path
18+
print(f"Percorso di Python 3.10 aggiunto a PATH: {python_path}")
19+
20+
# Verifica se python3.10 è disponibile dopo aver aggiornato PATH
21+
try:
22+
subprocess.check_call([python_path + r"\python.exe", "--version"])
23+
except subprocess.CalledProcessError:
24+
print("Errore: Python 3.10 non trovato o non configurato correttamente.")
25+
sys.exit(1)
26+
27+
# Esegui lo script con Python 3.10
28+
subprocess.check_call([python_path + r"\python.exe", os.path.abspath(__file__)] + sys.argv[1:])
29+
sys.exit() # Termina il processo attuale, in modo che non venga eseguito altro codice
530

631
def convert_to_wav(input_file, output_dir):
732
"""
@@ -76,6 +101,9 @@ def main(podcast_dir):
76101
print(f'Errore durante la trascrizione di {file_name}: {e}')
77102

78103
if __name__ == "__main__":
104+
# Verifica che Python 3.10 sia utilizzato
105+
ensure_python_3_10()
106+
79107
podcast_dir = input("Inserisci il percorso della cartella contenente i podcast: ").strip()
80108
if os.path.isdir(podcast_dir):
81109
main(podcast_dir)

0 commit comments

Comments
 (0)
Please sign in to comment.