顯示具有 python 標籤的文章。 顯示所有文章
顯示具有 python 標籤的文章。 顯示所有文章

2013年5月26日 星期日

The Free Translate API from Google

   The google translate api is not free in v2. but some way(hack) let it's work. we can sniff the Google Translate. and mimic the request, the example show as follow:

main.py
TRANSLATE_URL_PREFIX='http://translate.google.com.tw/translate_a/t?client=t&hl=zh-TW&sl=en&tl=zh-TW&ie=UTF-8&oe=UTF-8&multires=1&prev=enter&ssel=0&tsel=0&sc=1&q='
# the user agent is neccerry ...
query = "THE WORDS YOU WANT TO TRANSLATE"
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36'
headers = { 'User-Agent' : user_agent }
req = urllib2.Request(self.TRANSLATE_URL_PREFIX+query), None, headers)
res = urllib2.urlopen(req)
r = res.read()
while ',,' in r:
    r = r.replace(',,',',')
content = json.loads(r)
result = content[0][0][0]) 

The most trick is the response JSON is invalid. we should remove the wied tag : ",,".

hope it's help for you :)

2013年1月17日 星期四

smaf to wav solution


Survey

midi -> smaf(mmf,spf) -> wav
  1. midi-> smaf(mmf) : RetroCode<support MA2,3,5>
  2. smaf-> wav :
  • recorder software : total recorder, mp3mymp3(free), Audacity(free)
  • auto-play script : sikuli

    figure. the sikuli script
  • recording by python api : pyaudio
    recorder.py
    import pyaudio
    import wave
    p = pyaudio.PyAudio()
    stream = p.open(format = FORMAT,
                    channels = CHANNELS,
                    rate = RATE,
                    input = True)
                    #frames_per_buffer = chunk)
    print "* recording"
    all = []
    for i in range(0, RATE / chunk * RECORD_SECONDS):
        data = stream.read(chunk)
        all.append(data)
    print "* done recording"

Final version

System structure
Step by step
1. open stereo mode

figure. setting stereo mix mode on Windows 7
hint
the option is hidden on Windows 7
2. open recorder(server)
  • make sure the softwares
    • python 2.7
    • pyaduio
  • execution server
    • command line : #python server_recorder.py
    • IDEL : execfile("C:\server_recorder.py")
3. open player(client)
  • open mexa emulator
  • create folder /sampleData/jscl_storage_root/mc/(the StorageConnection use)
  • copy smaf music in /sampleData/jscl_storage_root/mc/MEXA/*.spf
  • running MIDlet
4. collection data
you can see the wav file in Default path - C:\Python27\smaf2wav\

Reference

python lib for midi
open source project for smaf player