1

i have a python script to slice wav file using start, end time. I want to execute this in arduino. can i run this directly into arduino? or if not, can you suggest idea how can i do this?

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
Biruntha G
  • 27
  • 2
  • 10

1 Answers1

0

If you are using an arduino mega you could take a look at PyMite.

For arduino uno there was a post (Is there a way to "compile" Python code onto an Arduino (Uno)?), about compiling python for arduino and in it there were mentioned two projects pyMCU and the other one in developement by a SOer, you could give it a try

But as they said, porting it to C++ is the easier way

Community
  • 1
  • 1
Mr. E
  • 2,070
  • 11
  • 23
  • @ Mr. E , can i run python file like this ? https://drive.google.com/file/d/0BzPUqBP4KQpjcWNHLWVOQjktR0U/view?usp=sharing – Biruntha G Nov 26 '15 at 03:44