常常有音頻轉文字的需求,訊飛聽見網站效果還不錯,贈送5小時免費轉寫時間,但用完了
想到訊飛有語音開放平臺,過去一看,轉寫SDK仍是要買時間,但語音聽打接口是免費的,那就試試
費了點勁註冊爲開發者,下載了LInux C SDK,測了下demo,沒問題。爲了速度,仍是用 Python 調接口吧,看上去 ctypes 實現比較天然。python
SDK 頭文件裏用enum定義了400+的錯誤碼,爲了方便調試,打算導成Python的enum定義(>=3.4)。手動拷貝感受不爽,並且裏面混雜着註釋less
SDK庫的符號表(被strip過了)
C語言分析器(不考慮)
手動清理複製(算了)網站
仍是用 gawk(比awk強大)處理下好了,比手動好點,說不許之後還能用...調試
BEGIN { RS = "\r\n|{|}|\n" # less is good for comment handling skip = 0 print "#!/usr/bin/env python3" print "# -*- coding: UTF-8 -*-", "\n" print "from enum import Enum", "\n" } { while ($1 == "") next } # skip one-line comment, no use? /^[[:blank:]]*(\/\/|#)/ { next } # skip comment /^[[:blank:]]*\/\*/, /\*\// { next } # get enum definitions /^enum/, /;/ { subn = 0 for (i=1; i<=NF; i++) { switch ($i) { case /^enum/: printf("class(Enum):") #header break case /^;$/: printf("\n") #tail next case /^(\/\/|\/\*)/: #skip comment next default: #body if (i == 1) printf("\t") subn = sub(/,/, "\n", $i) printf("%s ", $i) break } } if (subn == 0) printf("\n") } END { print "# end of", FILENAME }