How play mp3/audio files in Racket? - audio

I intend on making a cli audio player for racket, as an exercise to learn Racket, and everything else that would entail this project. I am stuck though how to begin. I can't find any package to play sound files, so I am guessing I may have to make one. How would I go about it?

What you probably want is #lang video (website). It provides a high level interface into audio playback. Allowing you to do something like:
#lang video
(clip "file.mp3")
Since you want to make a little command line player you might also want to take a look at its small preview tool.

I ended doing this the hackish way by calling a shell script via racket, not ideal at all. For reference, putting the code here.
; This creates the initail rsound
; for a song, this rsound is passed around
; so the whole song doesn't have to be
; decoded from the file everytime.
(define (play filepath)
(cond [(string=? "mp3" (last (regexp-split #rx"\\." filepath)))
(system* "./mp3-hack" filepath)
(set! filepath "curr.wav")])
(define input-pstream (make-pstream))
(define input-rsound (rs-read filepath))
(pstream-play input-pstream input-rsound)
(values input-pstream input-rsound filepath))
And the mp3-hack file just uses ffmpeg
#!/bin/sh
ffmpeg -i $1 -acodec pcm_s16le -ac 1 -ar 44100 curr.wav
Yeah, I know. Inelegant, but at least I got it working. I needed it for my hackathon project MPEGMafia

Related

Bulk audio watermarking with ffmpeg

I have about 10,000 audio files that I need to overlay with copyright sound. How can this be done with ffmpeg? Maybe there is a script for mass combining audio into one track?
If there is a simpler solution, I will be very grateful, since several days of googling did not lead to anything. Either I found programs without a job description, or solutions that only do one file at a time.
You can write a script for that depending your operating system. As I program with php, I would write a php CLI programme for this use case
Something like:
#!/usr/bin/php
// ensure ./new directory exists before running script
<?php
$dir = "/home/seb/Audio samples/";
$files1 = scandir($dir); //Get all the file from your $dir directory on your computer
foreach ($files1 as $myfile){
$mystring = "ffmpeg -i $myfile ./new/$myfile"; //Write here your FFMPEG command you want in a string
exec($mystring);
}
?>

Android java get wav file frames

I need to get waveform data from the wav file,but my code returns not right waveform (i compare my results with waveform from fl studio)
This is my code:
path = "/storage/emulated/0/FLM User
Files/My Samples/808 (16).wav";
waveb = FileUtil.readFile(path);
waveb = waveb.substring((int) (waveb.indexOf("data") + 4), (int)(waveb.length()));
byte[] b = waveb.getBytes();
for(int i= 0; i < (int)(b.length/4); i++) {
map = new HashMap<>();
map.put("value", String.valueOf((long)((b[i*4] & 0xFF) +
((b[i*4+1] & 0xFF) << 8))));
map.put("byte", String.valueOf((long)(b[i*4])));
l.add(map);
}
listview1.setAdapter(new
Listview1Adapter(l));
( (BaseAdapter)listview1.getAdapter()).notifyDataSetChanged();
My results:
Fl studio mobile results:
I'm not sure I can help, given what I know off of the top of my head, but perhaps this will trigger some ideas in your search for a solution.
It looks to me like you are assuming the sound file is 16-bit stereo, little-endian, and that you are only attempting to inspect one track of the stereo frame. Can you confirm this?
There's at least one way this plan could go awry: the .wav header may be an odd number of bytes in length, and you might not be properly parsing frame boundaries as a result. As an experiment, maybe try adding a different increment when you reference the b[] array? For example b[i4 + 1] and b[i4 + 2] instead of b[i4] and b[i4 + 1]. This won't solve the general problem of parsing .wav headers, but it could at least get you closer to understanding the situation.
It sure looks like Java's AudioInputStream is not accessible in Android, and all searches that I have that ask if there is an Android equivalent are turning up unanswered.
I've used AudioTrack for the playback of raw PCM, but I don't know an Android equivalent for reading wav files. The AudioRecord class and read() methods look interesting as the read methods store PCM data in a short array, but I've never used them, and they seem to be hard-coded to the microphone for input.
There used to be a Google Group: andraudio#googlegroups.com. IDK if it is still around. I used to go there and occasionally ask about things.
Maybe there is code you can use from Oboe or libGDX? The latter makes use of OpenAL and is for cross-platform development, with Android as one of the target platforms. I have not looked into either for this question.
If you do find the answer, it would be great to post it as a solution. This seems to be a matter that many have tried to solve and given up on.

Loop a Video on Echo Show

I'm building a skill for Echo Show and I've been trying to loop a video (mp4) file. I use the below code to play the video:
if (this.event.context.System.device.supportedInterfaces.VideoApp) {
this.response.playVideo(LINK);
} else {
this.response.speak("The video cannot be played on your device. " +
"To watch this video, try launching the skill from your echo show device.");
}
Unfortunately, regardless of which looping function I use, I either run into a general Amazon error or it simply plays the video once.
I've seen another post that kinda showed how to loop an audio file, but I haven't been able to apply similar logic to video.
Thanks in advance!
The problem is looping is not yet supported for VideoApp directive. You can use Video apl component to loop a video. https://developer.amazon.com/de/docs/alexa-presentation-language/apl-video.html

How would I play a .wav file with a Mathematica program?

I would like to know an easy way to implement a function playWav[filename_String] that plays a .wav file (as a side effect).
playSound[filename_String] := EmitSound # Import[filename, "WAV"]
Changing the "wav" to "Sound" allows it to play without GUI
playSound[filename_String] := EmitSound # Import[filename, "Sound"]

DTMF monitoring via multimon, awk and espeak

How to listen to the spoken DTMD digit every time the sound card capture one?
The objective is radio controlling my pc and interfaces activities dialing dtmf tones via a hand-held transceiver.
I used multimon to hear DTMF tones
I tried to use awk to filter digits and proceed accordingly.
For example, if I key "0" from the radio the system must reboot, etc, but first confirming the operation. " The computer will reboot, send # to confirm"...
I tried to use espeak for a voice confirmation to the remote radio.
The radio connected to the pc soundcard receives the commands and transmits the responses.
I do not simply know how to nest multimon within awk within espeak.
Multimon itself doesnt let me do anything with its stdout because its running ( do not terminate after hearing a digit, which is indeed right).
It would be extremely helpful if I knew how to just speak each digit, without exiting the natural multimon loop.
Say, multimon -a DTMF | awk'{print}' espeak -stdin
If this simply worked!
Is it possible to do? Any help wellcome.
3 years passed and still no advance in linux DTMF decoding.
Once I didnt see any DTMF Radio Controlling project in Linux, I plan to publish this shall I can solve this issue.
Thanks / Mario/ sao paulo brazil
I believe that my answer is out of date and perhaps you have found how to solve this.
I faced the same issue and figured out that the problem is in multimon. When you pipe the stdout from multimon to another program, multimon does not flush the verbose output properly.
Try to patch and recompile multimon, adding a "fflush(stdout);", like this:
(unixinput.c , around line 71 )
void verbprintf(int verb_level, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
if (verb_level <= verbose_level) {
vfprintf(stdout, fmt, args);
fflush(stdout); //ADD THIS LINE!!!!!!!!!!!!!!!
}
va_end(args);
}
Best regards,
-Eduardo
You can use the system() function to launch espeak from your awk script.
#OP, i am not clear about your question, but seeing that system() interests you, here's how you call external command in awk
multimon -a DTMF | awk '{
cmd="espeak "$0 #$0 comes from the multimon output
system(cmd)
}
'

Resources