func getNumChunks(filePath string) (int, error) {
	file, err := os.Open(filePath)
	if err != nil {
		return -1, errors.Trace(err)
	}
	defer file.Close()
	stat, err := file.Stat()
	if err != nil {
		return -1, errors.Trace(err)
	}
	wavFileSize := int(stat.Size())
	fileSplitSize := 95000000
	numChunks := wavFileSize/fileSplitSize + 1
	return numChunks, nil
}
getNumChunks gets file size in MB, divides by 95 MB, and add 1 more chunk in case
package transcription
import (
	"fmt"
	"io"
	"net/http"
	"net/smtp"
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"
	"time"
	"gopkg.in/kothar/go-backblaze.v0"
	"gopkg.in/mgo.v2"
	log "github.com/Sirupsen/logrus"
	"github.com/jordan-wright/email"
	"github.com/juju/errors"
	"github.com/hack4impact/transcribe4all/config"
)
func SendEmail(username string, password string, host string, port int, to []string, subject string, body string) error {
	auth := smtp.PlainAuth("", username, password, host)
	addr := host + ":" + strconv.Itoa(port)
	message := email.Email{
		From:    username,
		To:      to,
		Subject: subject,
		Text:    []byte(body),
	}
	if err := message.Send(addr, auth); err != nil {
		return errors.Trace(err)
	}
	return nil
}
func ConvertAudioIntoFormat(filePath, fileExt string) (string, error) {
	newPath := filePath + "." + fileExt
	os.Remove(newPath)  
	cmd := exec.Command("ffmpeg", "-i", filePath, "-ar", "16000", "-ac", "1", newPath)
	if out, err := cmd.CombinedOutput(); err != nil {
		return "", errors.New(err.Error() + "\nCommand Output:" + string(out))
	}
	return newPath, nil
}
func DownloadFileFromURL(url string) (string, error) {
	filePath := filePathFromURL(url)
	file, err := os.Create(filePath)
	if err != nil {
		return "", errors.Trace(err)
	}
	defer file.Close()
	response, err := http.Get(url)
	if err != nil {
		return "", errors.Trace(err)
	}
	defer response.Body.Close()
	_, err = io.Copy(file, response.Body)
	if err != nil {
		return "", errors.Trace(err)
	}
	return filePath, nil
}
func filePathFromURL(url string) string {
	tokens := strings.Split(url, "/")
	filePath := tokens[len(tokens)-1]
	filePath = strings.Split(filePath, "?")[0]
	filePath = filePath + strconv.Itoa(int(time.Now().UnixNano()))
	return filePath
}
func SplitWavFile(wavFilePath string) ([]string, error) {
	numChunks, err := getNumChunks(wavFilePath)
	if err != nil {
		return []string{}, errors.Trace(err)
	}
	if numChunks == 1 {
		return []string{wavFilePath}, nil
	}
	chunkLengthInSeconds := 2968
	names := make([]string, numChunks)
	for i := 0; i < numChunks; i++ {
		startingSecond := i * chunkLengthInSeconds
		if i > 0 {
			startingSecond -= 5
		}
		newFilePath := strconv.Itoa(i) + "_" + wavFilePath
		if err := extractAudioSegment(wavFilePath, newFilePath, startingSecond, chunkLengthInSeconds); err != nil {
			return []string{}, errors.Trace(err)
		}
		names[i] = newFilePath
	}
	return names, nil
}