Posts

Speech Recognition with Python3

### main.py

```
# https://www.codesofinterest.com/2017/03/python-speech-recognition-pocketsphinx.html

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
        try:
            #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="https://docs.bazel.build/versions/master/tutorial/cpp.html" %} The binary BUILD file may looks like this: cc_binary( name = "hello-world", srcs = ["hello-world.cc"], visibility = ["//visibility:public"] ) The library BUILD file may looks like this: cc_library( name = "hello-lib", srcs = ["hello-lib.cc"], hdrs = ["hello-lib.h"], visibility = ["//visibility:public"] ) How to use Gtest with Bazel? {% embed url="https://docs.bazel.build/versions/master/cpp-use-cases.html\#including-external-libraries" %} The final folder structure may looks like this: ├── external │   └── gtest.BUILD ├── lib │   ├── BUILD │   ├── hello-lib.cc │   └── hello-lib.h ├── main │   ├── BUILD │   └── hello-world.cc ├── test │   ├── BUILD │   └── hello-test.cc └── 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 ├── __init__.py ├── base.py ├── video.py └── web.py 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.video,auto_everything.web --output-dir=outputs 3. Then you will found you can use auto_everything.so 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 192.168.43.0/24 lookup 61
ip rule add from 192.168.42.0/24 lookup 61
ip route add default dev tun0 scope link table 61

ip route add 192.168.43.0/24 dev wlan0 scope link table 61
ip route add 192.168.42.0/24 dev wlan0 scope link table 61

ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61

ip route add 172.27.232.0/24 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