Using Remote Audio

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

bat112
New User
Posts: 2
Joined: Mon Jul 06, 2015 6:56 pm

Using Remote Audio

Postby bat112 » Mon Jul 06, 2015 7:05 pm

Did anybody tried to use the Remote Access and playing a wav file.

I connected to the EV3 via WLAN and i can control e.g. the motors etc... That works

Now i want to play a audio file (wav) via remote.

I tried to

Code: Select all

Audio sound = ev3.getAudio();
int i = sound.playSample(data, 1, 1, 8000, 8);


i also tried this

Code: Select all

RemoteAudio raudio2 = new RemoteAudio(raudio);
int j = raudio2.playSample(data, 1, 1, 8000, 8);


but nothing works?

any idea?

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Using Remote Audio

Postby gloomyandy » Mon Jul 06, 2015 9:50 pm

Firstly, welcome to the forum, secondly please take a little time to read the purpose of the various sections and please don't post questions asking for help in the development section. That section is intended as a place to discus development of leJOS. I have moved your topic to a more appropriate place.

Ok as to your question, what exactly are you trying to do? The code you have presented seems to be trying to play a single 1 byte sample that is at offset 1 in your data array. You also seem to be trying to set the volume level to 8 (which is not very high), are you sure this is what you wanted to do? At best this will produce a very quite click from the speaker! I think you need to provide a bit more information about what your code is actually doing and perhaps post a more complete example. Also have ou looked at and understood the API? Here is the API documentation for the call you are trying to use: http://www.lejos.org/ev3/docs/lejos/har ... t-int-int-
leJOS news https://lejosnews.wordpress.com/

bat112
New User
Posts: 2
Joined: Mon Jul 06, 2015 6:56 pm

Re: Using Remote Audio

Postby bat112 » Tue Jul 07, 2015 9:01 am

Thanks for your reply

I still read this docu but i get no successfull result because the docu is not clear also what you wrote.

I did some more testing

Code: Select all

ev3 = new RemoteEV3("192.168.2.15");
         ev3.setDefault();

         Path path = Paths.get("dog2.wav");
         byte[] data = Files.readAllBytes(path);
         Audio sound = ev3.getAudio();
         sound.systemSound(0); //This works
         int i = sound.playSample(data, 0, data.length, 8000, 50);
         System.out.println(i);

Now i here something like a "clattern" but not the original wav - file.


:-(

Any idea?


What you wrote is an 1 byte File.but the docu says

data - Buffer containing the samples
this is my byte wav file
offset - Offset of the first sample in the buffer
clear
len - Number of samples to queue
freq - Sample rate
vol - playback volume

Maybe here is an small bug in the docu


Thanks in advance Frank

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Using Remote Audio

Postby gloomyandy » Tue Jul 07, 2015 10:29 am

The document is correct, your samples are one byte long, so the number of samples to queue is the number of bytes to copy from your buffer. Are you sure that your file has been encoded correctly? In this case it must be 8 bit, mono, with a sample rate of 8000. Also a wav file will have a header on it your code will be trying to play that! It is not really a very good idea to play files remotely, you need to think what it is you will be asking the system to do here, if your wav file is more than a few seconds long you will need to split up the file into a series of requests, also you must check the return value of the call as it may not be possible to write all of the data in one go (in which case you will need to write the remainder in a second call). If you only have a few sounds you want to play, it will be much easier to copy the .wav file to the ev3 and then simply play it.
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 2 guests