[英]Run python script on arduino
我有一個使用開始,結束時間將wav文件切片的python腳本。 我想在arduino中執行此操作。 我可以直接在arduino中運行它嗎? 否則,您能否建議我該怎么做?
import wave
import pygame
import time
import sys
def slice(infile, outfilename, start_ms, end_ms):
width = infile.getsampwidth() #Returns sample width in bytes
rate = infile.getframerate() #Returns sampling frequency
fpms = rate / 1000 # frames per ms
length = (end_ms - start_ms) * fpms
start_index = start_ms * fpms
out = wave.open(outfilename, "w")
out.setparams((infile.getnchannels(), width, rate, length, infile.getcomptype(), infile.getcompname()))
infile.rewind() #Rewind the file pointer to the beginning of the audio stream
anchor = infile.tell() #Return current file pointer position
infile.setpos(anchor + start_index) #Set the file pointer to the specified position
out.writeframes(infile.readframes(length)) #Write audio frames and make sure nframes is correct
if __name__ == "__main__":
slice(wave.open("song1.wav", "r"), "out.wav", int(sys.argv[1]), int(sys.argv[2]))
pygame.mixer.init()
pygame.mixer.music.load("out.wav")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
continue
如果您使用的是arduino mega,則可以看看PyMite 。
對於arduino uno,有一篇文章( 有沒有一種方法可以將Python代碼“編譯”到Arduino(Uno)上? ),關於為arduino編譯python,在其中提到了兩個項目pyMCU ,另一個則由SOer開發,您可以嘗試一下
但是正如他們所說,將其移植到C ++是更簡單的方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.