diff --git a/API_reference.py b/API_reference.py index c00c733..0ad93ef 100644 --- a/API_reference.py +++ b/API_reference.py @@ -118,6 +118,7 @@ guan.plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', guan.download_with_scihub(address=None, num=1) # audio +guan.str_to_audio(str='hello world', rate=125, voice=1, read=1, save=0, print_text=0) guan.txt_to_audio(txt_path, rate=125, voice=1, read=1, save=0, print_text=0) content = guan.pdf_to_text(pdf_path) guan.pdf_to_audio(pdf_path, rate=125, voice=1, read=1, save=0, print_text=0) \ No newline at end of file diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index 7429fa8..025356a 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = guan -version = 0.0.14 +version = 0.0.15 author = guanjihuan author_email = guanjihuan@163.com description = An open source python package diff --git a/PyPI/src/guan/audio.py b/PyPI/src/guan/audio.py index 76bb8a1..138dfe2 100644 --- a/PyPI/src/guan/audio.py +++ b/PyPI/src/guan/audio.py @@ -2,6 +2,22 @@ # audio +def str_to_audio(str='hello world', rate=125, voice=1, read=1, save=0, print_text=0): + import pyttsx3 + if print_text==1: + print(str) + engine = pyttsx3.init() + voices = engine.getProperty('voices') + engine.setProperty('voice', voices[voice].id) + engine.setProperty("rate", rate) + if save==1: + engine.save_to_file(str, 'str.mp3') + engine.runAndWait() + print('MP3 file saved!') + if read==1: + engine.say(str) + engine.runAndWait() + def txt_to_audio(txt_path, rate=125, voice=1, read=1, save=0, print_text=0): import pyttsx3 f = open(txt_path, 'r', encoding ='utf-8')