ospalh / anki-addons

A collection of Anki 2.1 addons in different states of bugginess, up-to-dateness and usefulness.
http://ospalh.github.io/anki-addons/
135 stars 60 forks source link

Enable "play_button" to play the audio from internet for anki 2.1.x #123

Closed ecator closed 5 years ago

ecator commented 5 years ago

I have used the "Replay buttons on card" to play the audio from internet in anki 2.0.x, it likes this

py.link("ankiplayhttp......")

and in the anki 2.1.x , it changes to

pycmd("ankiplayhttp......")

but it couldn't work, so I fixed it. Thepycmd("ankiplayhttp://...") and pycmd("ankiplayhttps://...") can be used in JS now, I tested in macOS10.14 and win7 using anki 2.1.5.

Thanks.

ospalh commented 5 years ago

Hi. I don't know whether this really is something for general release. For example, why is the ".mp3" added at the end? That seems to be somewhat specific.

ecator commented 5 years ago

Sorry,I can't make sure it's general, I test some sites and it works both in mac and win7. You can add a note type in anki like this

<button onclick="pycmd('ankiplayhttp://www.abair.tcd.ie/audio/20181126_111007_001.mp3')">abair.ie</button>
<button onclick="pycmd('ankiplayhttps://fanyi.baidu.com/gettts?lan=en&text=Hello&spd=3&source=web')">Baidu</button>
<button onclick="pycmd('ankiplayhttps://www.collinsdictionary.com/sounds/2/241/24123/24123.mp3')">Collins</button>
<button onclick="pycmd('ankiplayhttps://translate.google.cn/translate_tts?ie=UTF-8&q=google&tl=en&total=1&idx=0&textlen=6&tk=212852.374263&client=t&prev=input}')">google</button>
<button onclick="pycmd('ankiplayhttp://cache-a.oddcast.com/tts/gen.php?EID=3&LID=1&VID=3&TXT=good&IS_UTF8=1&EXT=mp3&FNAME=&ACC=5883747&API=&SESSION=&CS=b2d6e3c82d6b813ac610acfcac99ba52&cache_flag=3')">oddcast</button>
<button onclick="pycmd('ankiplayhttps://audio1.spanishdict.com/audio?lang=es&text=bueno&key=c383870c6417d2754609f0461e515b3a')">spanishdict</button>
<button onclick="pycmd('ankiplayhttp://dws2.voicetext.jp/ASLCLCLVVS/JMEJSYGDCHMSMHSRKPJL/2018112620_3027_0398.mp3')">voicetext</button>
<button onclick="pycmd('ankiplayhttp://dict.youdao.com/dictvoice?audio=good&type=2')">Youdao</button>

The downloading operation as ".mp3" is only limited to windows. It seems to use mplayer in win and use mpv in mac or linux.

PS. I have asked the official whether anki2.1 can support the "audio" html element to play audio online, and the answer is no. 😭

ospalh commented 5 years ago

Thanks for the explanation, but i'm more of a fan of the "download once and keep the file" approach. See my audio downloader add-on. It even has code to try and get data from Collins Dictionary. Admittedly not for Anki 2.1. So, have fun with your addition, but i don't want to add this to my version of the add-on.