Christopher Konopka
Published © MIT

Remotely Play MP3 with Twilio, Go and Arduino MKR GSM 1400

How to play an MP3 file with Twilio Programmable Wireless, Go and the Arduino MKR GSM 1400.

BeginnerProtip3,861
Remotely Play MP3 with Twilio, Go and Arduino MKR GSM 1400

Things used in this project

Hardware components

Programmable Wireless
Twilio Programmable Wireless
×1
Arduino MKR GSM 1400
Arduino MKR GSM 1400
×1
GSM Antenna
×1
Mirco-USB cable
×1

Software apps and online services

Arduino IDE
Arduino IDE
Golang
Homebrew
Beep
ngrok

Story

Read more

Schematics

Arduino MKR GSM 1400 setup

Code

Code snippet #1

Plain text
void setup(){

}

void loop(){

}

Code snippet #9

Plain text
#include <MKRGSM.h>

GSM gsmAccess;
GSM_SMS sms;

void setup(){
    Serial.begin(115200);

    gsmAccess.begin();
    Serial.println("GSM initialized");
}

void loop(){
    sms.beginSMS("2936");

        sms.print("hello world");
        Serial.println(“Sending M2M Command”);

       sms.endSMS();
       Serial.println("M2M Command Sent!");

       while(1) {
               delay(4000);
       }  
}

Code snippet #10

Plain text
package main

import ( 

)

func main(){
}

Code snippet #11

Plain text
package main

import (
        "fmt"
    "github.com/faiface/beep"
    "github.com/faiface/beep/mp3"
    "github.com/faiface/beep/speaker"
    "log"
    "net/http"
    "os"
    "time"
)

Code snippet #16

Plain text
    f, err := os.Open("helloworld.mp3")
    if err != nil {
        log.Fatal(err)
    }
    s, format, _ := mp3.Decode(f)
    speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
    playing := make(chan struct{})
    speaker.Play(beep.Seq(s, beep.Callback(func() {
        close(playing)
    })))
    <-playing

Code snippet #17

Plain text
package main

import (
    "fmt"
    "log"
    "net/http"
    "os"
    "time"

    "github.com/faiface/beep"
    "github.com/faiface/beep/mp3"
    "github.com/faiface/beep/speaker"
)

func main() {
    http.HandleFunc("/helloworld", helloworld)
    http.ListenAndServe(":9999", nil)
}

func helloworld(w http.ResponseWriter, r *http.Request) {
    if err := r.ParseForm(); err != nil {
        log.Printf("Error parsing form: %s", err)
        return
    }

    pwCommand := r.PostFormValue("Command")
    fmt.Println("incoming Command from Arduino MKR GSM 1400 : ", pwCommand)

    fmt.Println("Playing audio file!")
    f, err := os.Open("helloworld.mp3")
    if err != nil {
        log.Fatal(err)
    }
    s, format, _ := mp3.Decode(f)
    speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
    playing := make(chan struct{})
    speaker.Play(beep.Seq(s, beep.Callback(func() {
        close(playing)
    })))
    <-playing
}

Github

https://github.com/faiface/beep

Github

https://github.com/arduino-libraries/MKRGSM

Gist

https://gist.github.com/cskonopka/fc82bbf81a47e901011a4281402178ea

Github

https://github.com/cskonopka/TwilioIoT

Credits

Christopher Konopka

Christopher Konopka

10 projects • 20 followers
I love connecting things

Comments