Affichage des articles dont le libellé est Newest questions tagged audio - Stack Overflow. Afficher tous les articles
Affichage des articles dont le libellé est Newest questions tagged audio - Stack Overflow. Afficher tous les articles

mercredi 18 février 2015

Detecting audio track playing from background app in iOS Swift

I'm creating a mood tracking app that, among other things, should use information about the songs the user listens to. Specifically, I'm interested in just extracting the titles that are otherwise visible from the locked screen view, when a track is playing. I've search the interwebs and have had no luck finding a solution to access this data using Swift.


Can anyone help?


How to interrcept and read audio data as it is being output in RaspberryPi

Specifically, I want to write a program to read audio data that is being output to the analog jack on a RaspberryPi that is running Pi MusicBox for a led visualizer. Previously I had a Processing sketch that could run on your average computer, but I am less experienced with ARM. I've considered writing a Java program to do this, but I haven't been able to find any good documentation.


Any help much appreciated, thanks!


mardi 17 février 2015

How do I stop playing a sound effect with SpriteKit and Swift?

I'm writing a storybook app for my niece and I have a question about SpriteKit. I'm trying to set it so that there are different types of audio that play.



  1. Background music that loops (AVFoundation)

  2. Narration that plays when on a new page, or when you press the narrate button to replay the narration (SKAction)


My problem is that the narration will play on top of each other if the user changes the page, or if the user plays the replay narration button. So it ends up sounding like two people talking over each other.


How can I stop all narrations that are playing when a new narration is triggered?


I can't find any relevant help on the internet. I've seen some posts saying us AVFoundation, but from my understanding (albeit limited) that seems more for the background music and can only have one track playing.


Am I misinterpreting the documentation? Can someone help me answer this problem?



import SpriteKit


import AVFoundation


class Page1: SKScene {



// MARK: Touch handling

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */

for touch: AnyObject in touches {
let location = touch.locationInNode(self)
println("\(location)")

//checks if someone touched the menu button
if menuButton.containsPoint(location) {
println("Play story with sound!")
settings.setInProgress()
goToPauseMenu()
}

if soundButton.containsPoint(location) {
println("Play story with sound!")
settings.setInProgress()
runAction(playNar)
}

//checks if someone touched the forward button
if pageForward.containsPoint(location) {
println("Next Page!")
settings.setInProgress()
nextPage()
}

}
}

Android media player : Stop buffering of audio stream on pause()

I am using Media player in my application, My application is totally depend on media player. I am streaming the music from the server. however, the streaming working perfectly.But I have to do some optimization as part of better performance of app and load balancing.I have to Stop buffering while user pause the music player.


Currently While i am playing the music player, music player Buffering can't stop while i pause the player. there is need to save bandwidth of the stream.It will save user data usage.and also server will save some process.


Please give me way how to stop buffering while music player pause?


however buffer will release on stop of music player.


My code is below



private MediaPlayer mMediaPlayer;
public String path = "mp3url";


mMediaPlayer = new MediaPlayer(this);
mMediaPlayer.setDataSource(path);
mMediaPlayer.prepare();
mMediaPlayer.start();

mMediaPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {

@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
// TODO Auto-generated method stub
Log.d("LOG", "Biffering update ||| "+percent);// it show that buffering cann't stop after pausing mediaplayer
}
});

Can't get jquery on click code to work

I'm having a problem with a piece of code which plays a short mp3/ogg file when a font awesome volume icon is clicked. The html works OK. The problem is with the js code



<p id="pathVar">/templates/beez_20/audio/dialogs/buy_flowers/</p>
<div id="dialog">
<div id="title_block">Buying flowers </div>
<div id="dlg_container">
<div id="audio_player" >{audio}Buying flowers|dialogs/buying_flowers/buying_flowers.mp3{/audio}</div>
<p class="dlg_content eng_dlg"><span class="dlg_text" id="bf01">Shopkeeper: Good afternoon, how can I help you?</span>&#xa0;<span class ="fa fa-volume-up fa-volume-up-dlg"></span> </p>
<p class="dlg_content eng_dlg"><span class="dlg_text">สวัสดีตอนบ่าย,มีอะไรให้ฉันช่วยไหม?</span></p>
...
</div></div>


js code



jQuery.noConflict();
jQuery(document).ready(function() {
jQuery("div#dlg_container").on("click",function (evnt) {
var elementId = evnt.target.id,
pathVar = document.getElementById("pathVar").innerHTML,
oggVar = pathVar+elementId+".ogg",
mp3Var = pathVar+elementId+".mp3",
audioElement = document.createElement("audio");
audioElement.src = Modernizr.audio.ogg ? oggVar : mp3Var;
audioElement.load();
audioElement.play();
});
});


Firebug shows that the elementId variable is nil, whereas it should contain, in example above, "bf01". I can't see why this is the case as similar code elsewhere works. I guess I'm missing something obvious here. Thanks in advance for any help.


Android, AOA2, USB Isochronous Audio Streaming

Using AOA v2 protocol, a android device can output its audio stream to some accessory connected over an USB. But is it possible for the accessory to send over its audio stream to android device so that the android device will act as an USB speaker?


I'm actually planning to write a USB speaker driver using AOA protocol, but I just got stuck here. Because I can make the device initialize in AOA mode, but can't get the endpoints for audio interface. So I kind of leaning towards to believe that audio input to android device isn't possible using AOA. Anyone has any experience with that?


How store iOS audio recordings on Parse?

Newbie iOS coder here, apologies if the answer is really simple.


So I set up my audio recording in viewDidLoad



// Set the audio file
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"MyAudioMemo.m4a",
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];

// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

// Define the recorder setting
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];

[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

// Initiate and prepare the recorder
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];


I have a bar button that records new audio files:



// Stop the audio player before recording
if (player.playing) {
[player stop];
}

if (!recorder.recording) {
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];

// Start recording
[recorder record];

} else {

// Pause recording
[recorder pause];
}

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Stop" style:UIBarButtonItemStylePlain target:self
action:@selector(stopTapped)];


Then the start becomes a stop button



[recorder stop];

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:NO error:nil];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"New" style:UIBarButtonItemStylePlain target:self
action:@selector(actionNew)];


How can I add this as a PFFile and save in a dictionary in Parse? I've read through a lot of the Parse documentation but still don't really get the hang of it. Any help much appreciated.


pauses during song playback in Raspberry Pi

I'm programing a playlist player in python using spotify and is running in Raspberry Pi. Everything is great just the songs have pauses during the playback. I done everything, update, check de ALSA driver, the code, I overclocking the raspberry, change the output between analog/HDMI, prefetch the song, but just still having pauses.


What am I doing wrong?



def player(session):

end_of_track = threading.Event()
global volume_effect

track = tracks[0]

def on_end_of_track(self):
end_of_track.set()

session.on(spotify.SessionEvent.END_OF_TRACK, on_end_of_track)
logger.info('End Track Event On')

session.player.prefetch(track)
session.player.load(track)
session.player.play()

logger.info('Playing: %r and %r', track.name, track.duration)

tracks.rotate(1)

logger.info('Next Song: %r', tracks[0].name)

if volume_effect == False:
for v in range(volume_min, volume_max, 5):
mixer.setvolume(int(v))
time.sleep(2)

volume_effect = True

try:
while not end_of_track.wait(track.duration/1000):
pass
except KeyboardInterrupt:
pass
else:
end_of_track.clear
session.player.unload()
player(session)

How can I reliably evaluate performance of Android app involving Audio recording and analysis

I am working on my masters thesis project titled "Speaker Detection and Conversation Analysis on Mobile Devices" which involves audio recording, feature extraction and analysis on Android phones. So I am developing an android app to test the hypothesis and to evaluate feasibility of doing it on Android in offline mode.


Currently I am done with Audio recording and feature extraction part. I have 3 different implementation using different toolkits. I have to evaluate performance of each project to decide which one to chose and take forward for next steps.


Battery Usage : My initial strategy is to record for 1 hour at least with phone in idle state and then with normal use, while dumping battery level at start and end of experiment. It will give me an idea about how much my android app contributes to battery consumption. Battery consumption is our major concern to test. Does it looks good ? Official documentation states that constantly monitoring battery usage actually adds up to more consumption.


CPU Consumption : I can also use http://ift.tt/1FcBZKx to evaluate performance of overall app or specific chunks of application like FFT module which are resource intensive.


Can I include any other parameter as well which is more suitable for app which involve audio processing ?


javascript AudioRecorder play sound from buffer

I am using cwilso/AudioRecorder http://ift.tt/1s0kdFP Demo: http://ift.tt/10MzWti


I can't figure out how to play the sound once recording is finished. Can somebody help please?


Using javax.sound to add background music

I'm not experienced in the topic, please understand. I am trying to add a background music to my game using javax.sound class. I tried many methods described in the internet, but none of them works. Please give me a simple class capable of playing background music. (I am using Eclipse)


Can't get audio file to play

I can't seem to figure out why my audio file won't play. The audio file is a wav file and is just. The error i am getting is javax.sound.sampled.UnsupportedAudioFileException.



public class MusicProgress {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame b = new JFrame();
FileDialog fd = new FileDialog(b, "Pick a file: ", FileDialog.LOAD);
fd.setVisible(true);
final File file = new File(fd.getDirectory() + fd.getFile());
//URI directory = new URI (fd.getDirectory() + fd.getFile());
try {
AudioInputStream inputStream = AudioSystem.getAudioInputStream(file);
AudioFormat audioFormat = inputStream.getFormat();
Clip clip = AudioSystem.getClip();
clip.open(inputStream);
clip.start();
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



}

}

IOS 8: Real Time Sound Processing and Sound Pitching - OpenAL or other framework

I'm trying to realize an app which plays a sequence of tones in a loop. Actually, I use OpenAL and my experiences with such framework are positive, as I can perform a sound pitch also.


Here's the scenario:



  1. load a short sound (3 seconds) from a CAF file

  2. play that sound in a loop and perform a sound shift also.


This works well, provided that the tact rate isn't too high - I mean a time of more than 10 milliseconds per tone.


Anyhow, my NSTimer (which embeds my sound sequence to play) should be configurable - and as soon as my tact rate increases (I mean less than 10 ms per tone), the sound is no more echoed correctly - even some tones are dropped in an obvious random way.


It seems that real time sound processing becomes an issue. I'm still a novice in IOS programming, but I believe that Apple sets a limit concerning time consumption and/or semaphore.


Now my questions:



  1. OpenAL is written in C - until now, I didn't understand the whole code and philosophy behind that framework. Is there a possibility to resolve my above mentioned problem making some modifications - I mean setting flags/values or overwriting certain methods?

  2. If not, do you know another IOS sound framework more appropriate for such kind of real time sound processing?


Many thanks in advance! I know that it deals with a quite extraordinary and difficult problem - maybe s.o. of you has resolved a similar one? Just to emphasize: sound pitch must be guaranteed!


Audio recording and playback option on HTML5

I am trying to develop a browser application that records the audio at 16kHz and has an option to play it back at 16kHz on HTML5.


I want the browser to be compatible with ios and android, primarily ios. What would be a good api to use to achieve this?


Write numpy array to wave file in buffers using wave (not scipy.io.wavfile) module

This caused me a day's worth of headache, but since I've figured it out I wanted to post it somewhere in case it's helpful.


I am using python's wave module to write data to a wave file. I'm NOT using scipy.io.wavfile because the data can be a huge vector (hours of audio at 16kHz) that I don't want to / can't load into memory all at once. My understanding is that scipy.io.wavfile only gives you full-file interface, while wave can allow you to read and write in buffers. I'd love to be corrected on that if I'm wrong.


The problem I was running into comes down to how to convert the float data into bytes for the wave.writeframes function. My data were not being written in the correct order. This is because I was using the numpy.getbuffer() function to convert the data into bytes, which does not respect the orientation of the data:



x0 = np.array([[0,1],[2,3],[4,5]],dtype='int8')
x1 = np.array([[0,2,4],[1,3,5]],dtype='int8').transpose()
if np.array_equal(x0, x1):
print "Data are equal"
else:
print "Data are not equal"
b0 = np.getbuffer(x0)
b1 = np.getbuffer(x1)


result:



Data are equal

In [453]: [b for b in b0]
Out[453]: ['\x00', '\x01', '\x02', '\x03', '\x04', '\x05']

In [454]: [b for b in b1]
Out[454]: ['\x00', '\x02', '\x04', '\x01', '\x03', '\x05']


I assume the order of bytes is determined by the initial allocation in memory, as numpy.transpose() does not rewrite data but just returns a view. However since this fact is buried by the interface to numpy arrays, debugging this before knowing that this was the issue was a doozy.


A solution is to use numpy's tostring() function:



s0 = x0.tostring()
s1 = x1.tostring()
In [455]: s0
Out[455]: '\x00\x01\x02\x03\x04\x05'

In [456]: s1
Out[456]: '\x00\x01\x02\x03\x04\x05'


This is probably obvious to anyone who say the tostring() function first, but somehow my search did not dig up any good documentation on how to format an entire numpy array for wave file writing other than to use scipy.io.wavfile. So here it is. Just for completion (note that "features" is originally n_channels x n_samples, which is why I had this data order issue to begin with:



outfile = wave.open(output_file, mode='w')
outfile.setnchannels(features.shape[0])
outfile.setframerate(fs)
outfile.setsampwidth(2)
bytes = (features*(2**15-1)).astype('i2').transpose().tostring()
outfile.writeframes(bytes)
outfile.close()

How to detect high volume and play something

I have searched the question and didn't find the answer. I have an Audio recorder and I want to edit the audio, play a sound of "STOP" voice when I hear a high volume. How can I detect a high volume, add a sound to that audio and get it in an AutdioRecorder audio?


HTML5/JavaScript library for audio record/play on iPhone device

I'm searching for web based solution to record 16kHz audio voice and play it on iPhone 5 and above devices. The existing solutions like recorder.js is only working on Chrome and FF.


Not allowing audio file to be played if its already playing

I have this code in my project -


-(IBAction)Bpm70:(id)sender{



CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"70bpm", CFSTR("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);

Timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(TimerCount) userInfo:nil repeats:YES];


}




  • the code starts a metronome audio file when the button is pressed, it also starts an NSTimer object.




  • Once the button is pressed I dont want the button to be able to be pressed again or audio file to play again) until the metronome audio file has finished playing.




Any help would be greatly appreciated, still relatively new to programming Thanks


how to play mp3 using javafx?

I am trying to play an mp3 file however I am getting an error: Cannot instantiate the type Media. I have no idea how to fix this error. I need the code to play the mp3 file, I also need to get the length of the song in millisecond. Here is my code:



import java.awt.FileDialog;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javafx.embed.swing.JFXPanel;
import javafx.scene.media.MediaPlayer;

import javax.print.attribute.standard.Media;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JFrame;

public class MusicProgress{
static URL url = null;

public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame b = new JFrame();
final JFXPanel fxPanel = new JFXPanel();
FileDialog fd = new FileDialog(b, "Pick a file: ", FileDialog.LOAD);
fd.setVisible(true);
//final File file = new File(fd.getDirectory()+ fd.getFile());
try{
final Media medias = new Media(fd.getDirectory()+ fd.getFile());
MediaPlayer mediaPlayer = new MediaPlayer(medias);
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

PULSEAUDIO does not list my ALSA capture device as a capture source

First of all, Hello eberybody!


I have recently written and ALSA driver for my audio capture card and I have problems with PULSEAUDIO recognising it as a capture source.


Here are some facts and hopefully one of you experienced this in the past and will be able to help:


(1) The capture card has 2 audio inputs (stereo): one HDMI and one analog. I can capture sound from both of them when using ALSA directly.


(2) When I use the PULSEAUDIO command to list audio capture sources:



$ pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2


The output shows the following, which are on-board devices and do not use my ALSA driver:



alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
alsa_input.pci-0000_00_1b.0.analog-stereo


Therefore, it can be seen from the above that my devices are not listed as capture sources.


(3) When I use:



$ pactl list


The output, among others, shows 'my' ALSA cards. Please see below 2 exemplary outputs: (a) for an on-board card (which does not use my driver) and (b) for the card which uses my driver:


(a) On-board card:



Card #0
Name: alsa_card.pci-0000_00_1b.0
Driver: module-alsa-card.c
Owner Module: 4
Properties:
alsa.card = "10"
alsa.card_name = "HDA Intel PCH"
alsa.long_card_name = "HDA Intel PCH at 0xfbf20000 irq 67"
alsa.driver_name = "snd_hda_intel"
device.bus_path = "pci-0000:00:1b.0"
sysfs.path = "/devices/pci0000:00/0000:00:1b.0/sound/card10"
device.bus = "pci"
device.vendor.id = "8086"
device.vendor.name = "Intel Corporation"
device.product.name = "6 Series/C200 Series Chipset Family High Definition Audio Controller"
device.form_factor = "internal"
device.string = "10"
device.description = "Built-in Audio"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-pci"
Profiles:
output:analog-stereo: Analogue Stereo Output (sinks: 1, sources: 0, priority. 6000)
output:analog-stereo+input:analog-stereo: Analogue Stereo Duplex (sinks: 1, sources: 1, priority. 6060)
output:analog-surround-40: Analogue Surround 4.0 Output (sinks: 1, sources: 0, priority. 700)
output:analog-surround-40+input:analog-stereo: Analogue Surround 4.0 Output + Analogue Stereo Input (sinks: 1, sources: 1, priority. 760)
output:analog-surround-41: Analogue Surround 4.1 Output (sinks: 1, sources: 0, priority. 800)
output:analog-surround-41+input:analog-stereo: Analogue Surround 4.1 Output + Analogue Stereo Input (sinks: 1, sources: 1, priority. 860)
output:analog-surround-50: Analogue Surround 5.0 Output (sinks: 1, sources: 0, priority. 700)
output:analog-surround-50+input:analog-stereo: Analogue Surround 5.0 Output + Analogue Stereo Input (sinks: 1, sources: 1, priority. 760)
output:analog-surround-51: Analogue Surround 5.1 Output (sinks: 1, sources: 0, priority. 800)
output:analog-surround-51+input:analog-stereo: Analogue Surround 5.1 Output + Analogue Stereo Input (sinks: 1, sources: 1, priority. 860)
input:analog-stereo: Analogue Stereo Input (sinks: 0, sources: 1, priority. 60)
off: Off (sinks: 0, sources: 0, priority. 0)
Active Profile: output:analog-stereo+input:analog-stereo
Ports:
analog-output: Analogue Output (priority 9900)
Part of profile(s): output:analog-stereo, output:analog-stereo+input:analog-stereo, output:analog-surround-40, output:analog-surround-40+input:analog-stereo, output:analog-surround-41, output:analog-surround-41+input:analog-stereo, output:analog-surround-50, output:analog-surround-50+input:analog-stereo, output:analog-surround-51, output:analog-surround-51+input:analog-stereo
analog-input-microphone: Microphone (priority 8700)
Part of profile(s): output:analog-stereo+input:analog-stereo, output:analog-surround-40+input:analog-stereo, output:analog-surround-41+input:analog-stereo, output:analog-surround-50+input:analog-stereo, output:analog-surround-51+input:analog-stereo, input:analog-stereo
analog-input-linein: Line In (priority 8100)
Part of profile(s): output:analog-stereo+input:analog-stereo, output:analog-surround-40+input:analog-stereo, output:analog-surround-41+input:analog-stereo, output:analog-surround-50+input:analog-stereo, output:analog-surround-51+input:analog-stereo, input:analog-stereo


(b) One of my cards (I have more than 1 card):



Card #11
Name: alsa_card.1
Driver: module-alsa-card.c
Owner Module: 31
Properties:
alsa.card = "1"
alsa.card_name = "OEM_VISIONRGB_AV"
alsa.long_card_name = "OEM_VISIONRGB_AV Analog DGC dada"
device.bus_path = "/devices/virtual/sound/card1"
sysfs.path = "/devices/virtual/sound/card1"
device.string = "1"
device.description = "OEM_VISIONRGB_AV"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card"
Profiles:
input:analog-stereo: Analogue Stereo Input (sinks: 0, sources: 1, priority. 60)
off: Off (sinks: 0, sources: 0, priority. 0)
Active Profile: input:analog-stereo
Ports:
analog-input: Analogue Input (priority 10000)
Part of profile(s): input:analog-stereo


Notice that the "Name" fields are much different in their form between my card and the on-board one. I tested that:




  • capturing from alsa_card.pci-0000_00_1b.0 (on_board card) works correctly.




  • it fails to capture from alsa_card.1 (my card).




Please note that my ALSA driver is still lacking some elements, for example, mixer element is not included and I presume it may be the reason for the lack of cooperation between ALSA and PULSEAUDIO. From your experience, do you know if mixer element is necessary for PULSEAUDIO to qualify ALSA devices as capture sources.


I do apologise for this verbose message. Nonetheless, does the above ring a bell?


Thanks a lot for your help and suggestions,


Przemek