Mini Maestro 12 playing audio

I want to write a script that does the following

  1. Send a serial command to play a MP3 file
  2. Move servos until the audio file stops playing

I am able to send a serial command in my script to play a MP3 file.

# play the file 0001.mp3 which if file #1
180 1 0 2 7 170 serial_send_byte serial_send_byte serial_send_byte serial_send_byte serial_send_byte serial_send_byte

# request current file number playing
183  13 170 serial_send_byte serial_send_byte serial_send_byte s 

The return of this command is 0 if no file is playing or a int16 value in my case 1.

But it does not appear there is a way to read the RX data returned so I can’t determine if the audio file is finished.

The alternative would be to know how long the MP3 file is and loop the servo movement for that amount of time. But I am not sure how to do that either.

This seems like a common requirement for any servo animatronics. How is it normally done?

1 Like

Hello.

The Maestro does not have any special features for syncing to audio like that. If you’re using the Maestro as your main controller, timing it out is probably the most practical solution. If you know how long the track is, and you know how long all of the delays in your sequence add up to, you can just use a while loop to loop a specific number of times.

Alternatively, you can use the GET_MS command to get the current millisecond timer after sending the command to start your audio track and use that as a reference to calculate how long it’s been since it has started, which could look something like this:

begin

  #start audio track here
  get_ms #put value of current millisecond timer on the stack

  begin dup get_ms swap minus 10000 less_than while 
    #run the code inside the while loop for the next 10000ms
  repeat

  drop quit #clear the stack and stop the script
repeat

Some MP3 playback boards have a digital output that indicates when audio is playing, so if yours has something like that, using it as an input to a Maestro channel is another possible solution.

Brandon

The DY-HV8F board I am using has a busy pin that is 0V when playing and 3.3V when not playing

I could wire that to a channel on the Maestro like suggested. And loop until that chanel goes high. Would that work?

Yes, that should work. You can configure the channel you’re using to monitor the audio board’s output as an “Input” in the “Channel Settings” tab of the Maestro Control Center and have your script check it using the get_position command.

All of the channels on the 12-channel Maestro act as analog inputs when configured as an input; the readings are between 0 and 1023 corresponding to voltages between 0V and 5V. Please note that the value shown in the “Status” tab will be 1/4 of this reading, varying from 0 to 255μs in quarter microsecond increments.

Brandon

Any chance you could provide a quick code snip of a script that would check that the channel position value?

I am thinking I will have a servo routine that is much shorter than the audio file so it will repeat until the audio is done

serial_sendbyte - play sound
do while get_position of channel 6 > 0
playservo frames

loop

Hello.

That kind of script would look something like this with the Maestro’s scripting language:

begin

  #trigger sound to play here

  begin  6 get_position 400 less_than while  #while input on channel 11 is less than 400
    #put servo sequence here
  repeat

repeat

Please note that this example uses the input on channel 6; if you need to, you can change the channel number by changing the 6 before the get_position command.

Brandon

based on the example. If I understand correctly. You are testing for the channel value to be less than 400 because the reading can be 0 - 1023 (corresponds to voltage 0V - 5V). So 400 would be a voltage of ~ 1.9V or basically a low signal? My audio board puts out 0V on the busy pin when audio is playing and when done sets the pin to 3.3V.

Just want to make sure that is what you were meaning to show.

It sounds like you understand it correctly. 6 get_position should return approximately 0 when the audio is playing and 675 when the audio is done. 400 less_than will test if the returned value is less than 400. If it is, it will return 1 otherwise it will return 0. (You don’t have to use 400 as a threshold; I just picked an arbitrary value between 0 and 675.) The result (0 or 1) is then used by the while command.

Brandon