Skip to content

Commit

Permalink
v2.1.3_70
Browse files Browse the repository at this point in the history
*src/libaudio.py,src/libnetwork.py 换用了新的tts引擎
*src/libgui.py 修复了下载音频时进度条不走,结束时直接从0走到100%的问题
*makefile 优化实现方式,增加打包前填写必要数据的提示
-libnetwork.py 删除无用代码
  • Loading branch information
BailPlus committed Jun 30, 2024
1 parent 306371d commit 0339682
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 79 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
白杉树背单词训练软件 更新日志
2024.6.30:v2.1.3_70
*src/libaudio.py,src/libnetwork.py 换用了新的tts引擎
*src/libgui.py 修复了下载音频时进度条不走,结束时直接从0走到100%的问题
*makefile 优化实现方式,增加打包前填写必要数据的提示
-libnetwork.py 删除无用代码
2024.6.30:v2.1.2_69
-src/libaudio.py 取消了下载音频时对tqdm的依赖(无用功能)
*src/libaudio.py 优化了下载音频时显示进度百分比的方式,解决了单词数量较多时下载界面提前退出的bug
Expand Down
12 changes: 9 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ build-linux:
cp res/bss.png build/linux/usr/share/pixmaps
cp changelog.txt LICENSE build/linux/usr/share/bssenglish
chmod 755 build/linux/usr/bin/bssenglish
echo 所有文件已准备完成,请填写版本号、包大小等信息。完成后,按回车键继续
read a
dpkg -b build/linux bssenglish_linux.deb
build-deepin:
patch -p0 src/bss.py <patch/deepin.patch
patch src/bss.py patch/deepin.patch
cp src/bss.py src/init.py src/install_requires.py src/lib*.py changelog.txt LICENSE build/deepin/opt/apps/com.Bail.bssenglish/files
cp res/bss.png build/deepin/opt/apps/com.Bail.bssenglish/files/
chmod 755 build/deepin/opt/apps/com.Bail.bssenglish/files/bss.py
echo 所有文件已准备完成,请填写版本号、包大小等信息。完成后,按回车键继续
read a
dpkg -b build/deepin bssenglish_deepin.deb
build-termux:
patch -0 src/bss.py <patch/termux.patch
patch src/bss.py patch/termux.patch
cp src/bss.py build/termux/data/data/com.termux/files/usr/bin/bssenglish
cp src/bss.py src/init.py src/install_requires.py src/lib*.py build/termux/data/data/com.termux/files/usr/lib/bssenglish
cp src/init.py src/install_requires.py src/lib*.py build/termux/data/data/com.termux/files/usr/lib/bssenglish
cp res/bss.png build/termux/data/data/com.termux/files/usr/share/pixmaps
cp changelog.txt LICENSE build/termux/data/data/com.termux/files/usr/share/bssenglish
chmod 755 build/termux/data/data/com.termux/files/usr/bin/bssenglish
echo 所有文件已准备完成,请填写版本号、包大小等信息。完成后,按回车键继续
read a
dpkg -b build/termux bssenglish_termux.deb
clear:
git checkout -- .
2 changes: 1 addition & 1 deletion src/bss.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python3
#coding:utf-8
#Copyright Bail 2021-2024
#bssenglish 白杉树背单词训练软件 v2.1.2_69
#bssenglish 白杉树背单词训练软件 v2.1.3_70
#2021.7.11-2024.6.30

'''
Expand Down
9 changes: 3 additions & 6 deletions src/libaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ def download(root:libgui.Tk,lesson:libclass.Lesson):
update = libgui.download(root,len(wlst))
try:
for index,i in enumerate(wlst):
if f'{i}.mp3' not in files:
if ' ' in i.word: #词组(搜狗tts引擎)
libnetwork.getaudio1(i.word)
else: #单词(搜狗美式发音)
libnetwork.getaudio2(i.word)
if f'{i.word}.mp3' not in files:
libnetwork.getaudio(i.word)
update(index)
update(index+1)
except:
except Exception:
libgui.msgbox.showerror('错误','无法下载,请检查网络连接',parent=root)
raise
def play(word:libclass.Word):
Expand Down
2 changes: 1 addition & 1 deletion src/libgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def download(root:Tk,wordnum:int):
wordnum(int):单词数量
返回值:用于更新进度条的函数(func)'''
def update(value:int):
per = int(value/wordnum)*100
per = int(value/wordnum*100)
bar['value'] = per
label['text'] = f'{per}%'
down.update()
Expand Down
84 changes: 16 additions & 68 deletions src/libnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,23 @@

APISOURCE = 'https://bailplus.github.io/bssenglish.pages/api/'

import requests,libfile,os,webbrowser
import requests,libfile,os,webbrowser,asyncio,edge_tts

'''https://tts.baidu.com/text2audio?cuid=baike&lan=en&ctp=1&pdt=301&vol="+vol+"&rate=32&spd="+spd+"&per="+per+"&tex="+a
spd 语速 default:5
per 语调 1-6 default:4
vol 音量 5
a 文本内容'''
'https://fanyi.sogou.com/reventondc/synthesis?text=hello&speed=1&lang=en&from=translateweb&speaker=1'
'https://dlweb.sogoucdn.com/phonetic/{word}DELIMITER_us_1.mp3'

"""def getaudio(word:str,lan:str='en',spd:int=5,per:int=1,vol:int=5)->str:
'''获取音频并下载(百度tts引擎,已失效)
word(str):单词
lan(str):语种(zh,en,jp,...)
spd(int):语速
per(int:1-6):语调
vol(int):音量
返回值:音频文件路径(str)'''
PATH = os.path.join(libfile.getpath('audio'),f'{word}.mp3')
url = 'https://tts.baidu.com/text2audio'
params = {'cuid':'baike',
'lan':lan,
'ctp':1,
'pdt':301,
'vol':vol,
'rate':32,
'spd':spd,
'per':per,
'text':word,
'ie':'utf-8'}
#访问
response = requests.get(url,params=params,timeout=5)
#存储
with open(PATH,'wb') as file:
file.write(response.content)"""
def getaudio1(word:str,lan:str='en',spd:int=1)->str:
'''获取音频并下载(搜狗tts引擎)
word(str):单词
lan(str):语种(zh,en,jp,...)
spd(int):语速
per(int:1-6):语调
vol(int):音量
返回值:音频文件路径(str)'''
PATH = os.path.join(libfile.getpath('audio'),f'{word}.mp3')
url = 'https://fanyi.sogou.com/reventondc/synthesis'
params = {'lang':lan,
'speed':spd,
'text':word,
'ie':'utf-8'}
#访问
response = requests.get(url,params=params,timeout=5)
#存储
with open(PATH,'wb') as file:
file.write(response.content)
def getaudio2(word:str):
'''获取音频并下载(搜狗美式发音)
word(str):单词
返回值:音频文件路径(str)'''
PATH = os.path.join(libfile.getpath('audio'),f'{word}.mp3')
url = f'https://dlweb.sogoucdn.com/phonetic/{word}DELIMITER_us_1.mp3'
#访问
response = requests.get(url,timeout=5)
#查错
if b'<html>' in response.content:
getaudio1(word)
return
#存储
with open(PATH,'wb') as file:
file.write(response.content)
async def run_tts(text:str,output:str,voice:str='en-US-JennyNeural'):
'''调用tts获取音频
text(str):需要转语音的文本
output(str):输出文件路径
voice(str):音色,详见下述文档
--------------
特别鸣谢:edge-tts项目
项目地址:https://github.com/rany2/edge-tts/
(非官方)文档地址:https://www.bingal.com/posts/edge-tts-usage/'''
await edge_tts.Communicate(text,voice).save(output)
def getaudio(word:str):
'''获取音频并下载
word(str):单词'''
path = os.path.join(libfile.getpath('audio'),f'{word}.mp3')
asyncio.run(run_tts(word,path))
def open_browser_to_fetch_lessons(url='https://bailplus.github.io/bssenglish.pages/lessons'):
'''使用浏览器打开“获取课程”界面
url(str):要打开的网址'''
Expand Down

0 comments on commit 0339682

Please sign in to comment.