Skip to content

Commit

Permalink
0.0.2 release!
Browse files Browse the repository at this point in the history
  • Loading branch information
CypherousSkies committed Oct 4, 2021
1 parent eb6b485 commit ea7179b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 19 deletions.
45 changes: 41 additions & 4 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 39 additions & 14 deletions r4l/bin/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import sys

from r4l.util.text import TextProcessor
from r4l.util.reader import Reader
from r4l.util.reader import Reader, models_dict
import os
import time
import csv
Expand All @@ -11,14 +13,22 @@
os.environ["TOKENIZERS_PARALLELISM"] = "False"
tag_remover = re.compile('<.*?>')

def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ("yes", "true", "t", "y", "1"):
return True
if v.lower() in ("no", "false", "f", "n", "0"):
return False
raise argparse.ArgumentTypeError("Boolean value expected.")

def get_ext(filename):
return filename.split(".")[-1]


def get_texts(sesspath, force_english):
def get_texts(sesspath, lang, force_english):
wordcount = 0
tp = TextProcessor()
tp = TextProcessor(sc_langs=lang)
files = [f for f in os.listdir(sesspath) if get_ext(f) in ['pdf', 'txt', 'muse']]
texts = [[] for _ in files]
print(f"> Reading {files}")
Expand All @@ -43,8 +53,8 @@ def get_texts(sesspath, force_english):
return texts, files, wordcount


def read_texts(texts, files, outpath):
reader = Reader(outpath, lang='en')
def read_texts(texts, files, outpath, lang):
reader = Reader(outpath, lang=lang)
for text, name in zip(texts, files):
reader.tts(text, name)
return
Expand All @@ -56,27 +66,42 @@ def main():
"""In the interests of user-friendliness, this cli will be kept pretty bare-bones"""
"""
Basic usage:
$ ./r4l/bin/cli.py [--in_path in/] [--out_path out/]
will convert (english language) pdfs in the folder "in/" and output mp3s to the folder "out/"
$ r4l [--in_path in/] [--out_path out/] [--lang "en"]
Converts pdfs, txts, muses in the folder "in/" and output mp3s to the folder "out/" with the primary language set to "en"
List languages:
$ r4l --list_languages
Lists available languages (Warning! Not tested on non-latin scripts!)
"""
)
parser.add_argument("--in_path", type=str, default="in/", help="Path containing pdfs to be converted")
parser.add_argument("--out_path", type=str, default="out/", help="Output path")
parser.add_argument("--in_path", type=str, default="in/", help="Path containing files to be converted.")
parser.add_argument("--out_path", type=str, default="out/", help="Output path.")
parser.add_argument("--lang", type=str, default="en", help="Two-letter language code.")
parser.add_argument(
"--list_langs",
type=str2bool,
nargs="?",
const=True,
default=False,
help="list available languages.",
)
args = parser.parse_args()
if args.list_langs:
print(models_dict.keys())
sys.exit()
if not os.path.isdir(args.in_path):
print("input path must exist and contain files!")
parser.parse_args(["-h"])
if not os.path.isdir(args.out_path):
os.mkdir(args.out_path)
run(args.in_path, args.out_path)
run(args.in_path, args.out_path, args.lang)
return


def run(in_path, out_path):
def run(in_path, out_path, lang):
start_time = time.time()
force_english: bool = False
texts, files, wordcount = get_texts(in_path, force_english)
read_texts(texts, files, out_path)
texts, files, wordcount = get_texts(in_path, lang, force_english)
read_texts(texts, files, out_path, lang)
time_taken = time.time() - start_time
with open('time_data.csv', 'a') as f:
writer = csv.writer(f)
Expand All @@ -86,4 +111,4 @@ def run(in_path, out_path):


if __name__ == "__main__":
run("in/", "out/")
run("in/", "out/", "en")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
readme = f.read()
setup(
name='reading4listeners',
version='0.0.1',
version='0.0.2',
packages=['r4l'],
url='https://github.com/CypherousSkies/reading-for-listeners',
license=legal,
Expand Down
1 change: 1 addition & 0 deletions time_data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
544,101.4726173877716
544,69.36171174049377
544,95.81861162185669
544,83.5948269367218

0 comments on commit ea7179b

Please sign in to comment.