Sound.playSample()

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

Moderators: roger, gloomyandy, skoehler

moo
New User
Posts: 23
Joined: Thu Apr 06, 2017 2:43 am

Sound.playSample()

Postby moo » Thu Apr 13, 2017 2:18 am

I am unable to get ev3 to play wav sound file. I have no problem playing tones. What am I doing wrong??

I created wav file using two separate methods.
1. Audacity program to record and save the file as "WAV (Microsoft) signed 16 bit PCM"
2. recorded using quicktime and converted using
http://audio.online-convert.com/convert-to-wav (PCM unsigned 8bit)

public void run() {

System.out.println("haha");
File file=new File("singing2_converted.wav");
if(!file.exists())
System.out.println("File does not exist!");
Sound.playSample(file);

System.out.println("completed");
System.out.println(file.getName());
}

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

Re: Sound.playSample()

Postby gloomyandy » Thu Apr 13, 2017 7:17 am

What is the return value from playSample? As you can see from the source:
https://sourceforge.net/p/lejos/ev3/cod ... Audio.java
The return code may help you work out what is wrong.
leJOS news https://lejosnews.wordpress.com/

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

Re: Sound.playSample()

Postby gloomyandy » Thu Apr 13, 2017 7:18 am

My best guess is that your sample is not a mono one...
leJOS news https://lejosnews.wordpress.com/

moo
New User
Posts: 23
Joined: Thu Apr 06, 2017 2:43 am

Re: Sound.playSample()

Postby moo » Thu Apr 13, 2017 1:07 pm

How do I create correct format? What program should I use?

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

Re: Sound.playSample()

Postby gloomyandy » Thu Apr 13, 2017 3:58 pm

You need to tell us what the error is before we can be sure that it is a format problem. So what is the return code from the call to playSample, print it out on the screen and post the results here.

As to what program to use there are lots of programs that will let you create wav files. The ones you have tried already may well be fine, you just need to select the right options. Probably the best settings are 16 bit pcm, mono, The sample rate should probably be something like 24KHz or maybe 32KHz.
leJOS news https://lejosnews.wordpress.com/

moo
New User
Posts: 23
Joined: Thu Apr 06, 2017 2:43 am

Re: Sound.playSample()

Postby moo » Thu Apr 13, 2017 5:11 pm

I didn't know that the method returns error code. I will try out the suggested settings and post back here the outcome next week.

moo
New User
Posts: 23
Joined: Thu Apr 06, 2017 2:43 am

Re: Sound.playSample()

Postby moo » Wed Apr 19, 2017 2:09 am

i was able to get it to work. However, volume is pretty low I must say.

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

Re: Sound.playSample()

Postby gloomyandy » Wed Apr 19, 2017 2:26 pm

Yep that's what you get with a very small speaker and a low power amp! One thing though. You can make things louder by using compression on the sample and encoding the sample so that the levels within it are higher. It will not be HiFi but it will be louder. Oh and I asume you have the volume set to max?
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest