UPDATE: if you are working with personal mp wechat, you can register a test account which is full privilege, or you can register a company account(choose team, not a real company)
mplayer plays better than
You need a wechat certificated mp account, because you need a privilege only certificated account can acquire.
When I almost finished the project, I found I can't acquire that privilege, so I can't get the voice file from API.
config interface endpoint
Recommended encrypted mode, but you must implement encryption and decryption methods for communication with wechat API.
You must implement your endpoint first, because wechat will test your endpoint when you config that, wechat will visit you endpoint with some arguments:
echostr, if you choose non-encrypt mode, you just return the
echostr content, the test will be ok, otherwise, you must return a encrypted content.
process voice message
When a voice message sent to your mp account, wechat will call your endpoint, a
POST request will be received, the
request body is a
XML message, you can use any tools you like to parsing that, I recommended python's built-in xml library, because complie
lxml is too slow in raspberry pi (I have waiting for 10+ minutes).
get voice file
The content sent to your endpoint included a
media id, you can use this and your
access token get voice file from API.
access token is the certificate for calling API, you can acquire it with your
app id and
app secret, it will expired within 7200s, so you need store it and acquire it if it has expired.
If you have privilege to get media file (you're luck), you will get the voice file, maybe it's
amr format, you need store it and play it with
mplayer, it's the built-in player for raspberry.
The Github: https://github.com/dawncold/raspsound
Subscribe to TradeOff
Get the latest posts delivered right to your inbox