Add dotenv, fixed requirements.txt

This commit is contained in:
Reza Behzadan 2023-12-11 02:56:31 +03:30
parent 5add45c71c
commit 32a9ab07ac
3 changed files with 23 additions and 14 deletions

2
.env.sample Normal file
View File

@ -0,0 +1,2 @@
MODEL="m3hrdadfi/wav2vec2-large-xlsr-persian"
LOG_LEVEL="INFO"

25
main.py
View File

@ -1,20 +1,27 @@
import logging
import os
import warnings
import librosa
import transformers
import torch
from dotenv import load_dotenv
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
# MODEL = "m3hrdadfi/wav2vec2-large-xlsr-persian"
MODEL = "/home/reza/data/huggingface-models/04.wav2vec2-large-xlsr-persian"
warnings.filterwarnings("ignore")
transformers.logging.set_verbosity_error()
load_dotenv()
MODEL = os.getenv("MODEL", "m3hrdadfi/wav2vec2-large-xlsr-persian")
LOG_LEVEL = os.getenv("LOG_LEVEL", "DEBUG")
def initLogger(name=__name__, level=logging.DEBUG):
if name[:2] == '__' and name[-2:] == '__':
name = name[2:-2]
logger = logging.getLogger(name)
def initLogger():
logger = logging.getLogger("speech2text-fa")
level = getattr(logging, LOG_LEVEL.upper())
fmt = '%(asctime)s | %(levelname)-8s | %(name)s | %(message)s'
datefmt = '%Y-%m-%d %H:%M:%S'
fmt = "%(asctime)s | %(levelname)-8s | %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter(fmt, datefmt)
@ -49,7 +56,7 @@ def mp3_to_text(mp3_file_path):
if __name__ == "__main__":
logger = initLogger('speech2text_fa', level=logging.INFO)
logger = initLogger()
text = mp3_to_text("samples/sample1.wav")
print()
print(text)

View File

@ -1,6 +1,6 @@
torch==2.1.1+cpu
torchaudio==2.1.1+cpu
transformers==4.35.2
https://download.pytorch.org/whl/cpu/torch-2.1.1%2Bcpu-cp311-cp311-linux_x86_64.whl#sha256=d83b13cb17544f9851cc31fed197865eae0c0f5d32df9d8d6d8535df7d2e5109
https://download.pytorch.org/whl/cpu/torchaudio-2.1.1%2Bcpu-cp311-cp311-linux_x86_64.whl#sha256=e0eb276958fcbd7c88f5daf761823e36ce5e41332d40f9e01fb49d80d7cc1bb1
librosa==0.10.1
--find-links https://download.pytorch.org/whl/cpu
python-dotenv==1.0.0
tokenizers>=0.10.1,<0.11
transformers>=4.16.2,<4.17.0