Speech Recognition with Python3



import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()

with sr.Microphone() as source:
    print("Please wait. Calibrating microphone...")
    r.adjust_for_ambient_noise(source, duration=5)

    while 1:
        print("\nSay something!")
        audio = r.listen(source)

        # recognize speech using Sphinx
            #print("Google thinks you said '" + r.recognize_google(audio, language="zh-CN") + "'")
            print("Sphinx thinks you said '" + r.recognize_sphinx(audio, language="en-US") + "'")
        except sr.UnknownValueError:
            print("Sphinx could not understand audio")
        except sr.RequestError as e:
            print("Sphinx error; {0}".format(e))



Use Bazel and Gtest

Why Bazel? Because cmake or make is too hard to learn. How to learn Bazel? Follow its instruction on official website: {% embed url="" %} The binary BUILD file may looks like this: cc_binary( name = "hello-world", srcs = [""], visibility = ["//visibility:public"] ) The library BUILD file may looks like this: cc_library( name = "hello-lib", srcs = [""], hdrs = ["hello-lib.h"], visibility = ["//visibility:public"] ) How to use Gtest with Bazel? {% embed url="\#including-external-libraries" %} The final folder structure may looks like this: ├── external │   └── gtest.BUILD ├── lib │   ├── BUILD │   ├── │   └── hello-lib.h ├── main │   ├── BUILD │   └── ├── test │   ├── BUILD │   └── └── WORKS…

Use Nuitka to compile Python Codes to Binary file

Why I say Python is better than C/C++Python is made for human (codes writing like English speaking)Python can be running at every platform after you compile it to binary file by using Cython or NuitkaPython has countless packages also was intended for humans How to compile Python codes to binary? 1. Let’s say you have a package in this structure:└── auto_everything ├── ├── ├── └── 2. After Nuitka was installed, run the following commands:cd .. python3 -m nuitka --module auto_everything --output-dir=outputs
or cd .. python3 -m nuitka --module auto_everything --include-package=auto_everything.base,,auto_everything.web --output-dir=outputs 3. Then you will found you can use like this:# cd outputs && python3import auto_everything
or # cd outputs && python3from auto_everything.base import Terminalt = Terminal() print(t.run_command("echo hi"))

Mastering iptables, ip (iproute2)

After you enabled your hotspot and VPN on your android phone, the following commands could be used to let all devices who connected to your hotspot to have the ability to enjoy the VPN without any further work.

iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -A FORWARD -j ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE

ip rule add from lookup 61
ip rule add from lookup 61
ip route add default dev tun0 scope link table 61

ip route add dev wlan0 scope link table 61
ip route add dev wlan0 scope link table 61

ip route add broadcast dev wlan0 scope link table 61

ip route add dev tun0 table 61

iptables -t filter -F FORWARD

* -t means `table`
* -F means `flush`.  flush = clear = delete

> Filter: filter is the default table. Its built-in chains are Input, Forward, Output

Delete all rules at the `Forward Chain`

> Forward: send packets from one network(LAN or W…

Convert PDF to searchable PDF

For Chinese:
ocrmypdf -l chi_sim --deskew --title "yingshaoxo's pdf" --jobs 3 --output-type pdfa input.pdf output_searchable.pdf

For English:
ocrmypdf -l en --deskew --title "yingshaoxo's pdf" --jobs 3 --output-type pdfa input.pdf output_searchable.pdf

Golang for Android Development

#### It's good to write Golang for producing binary file, then use it everywhere

>`Cython` could do the same thing by convert python to c, then c to binary.
##### First, you should write a program at `~/go/github/yingshaoxo/hi/main.go`
``` package greeting
func SayHi() string { return "Hi!" } ```
> Capitalize the function name, so golang would treat that function as public.
##### Then, compile it to binary file

Quickly start to use vifm

`vifm` is awesome!

Use `tab` to switch tab
Use `zo`  to show hidden file
Use `zm` to hide hidden file
Use `? regular_expression` to find a file at current list
Use `:find *.jpg` to find a file at sub directory recursively
Use `yy` to copy file, `p` to paste
Use `dd` to delete or move a file
Use `cw` for renaming
Use `:touch hi.txt` to create a new txt file
Use `:shell` to enter shell
Add `filetype * nohup gnome-open >/dev/null 2>&1 &` to the top of `~/.config/vifm/vifmrc`, so it can know how to open a file with default program