Hi, It would appear the the 'pcm2speex.read(frame, 0, frame.length)' is blocking which means that it is waiting for data from the underlying inputstream (i.e.AudioInputStream(t.input)). If it could read sufficient data it would transcode it. If it recieved an EOF, it should do some zero padding and then transcode it. Are you sure that you are receiving data from the underlying inputstream??? One point to note though is that is you are receiving 44kHz audio, it will try to encode this as UWB (i.e. pretending it's 32kHz sampling rate), which means that to encode 1 speex packet you are going to need 640 samples, or 1280 bytes (which should compress down to something like 29 bytes because the quality setting should be 3 by default). Having said this, jspeex does provide an SPI interface so you should be able to ask JavaSound to give you directly a a Speex AudioInputStream. It's coded although I admit that I never got round to testing it so it might not work. It does work for the decoding, that I'm sure of in any case. Marc Gimpel Head of research Wimba Ulrich B. Staudinger wrote:> Ulrich B. Staudinger wrote: > >> Hi, >> >> i have: >> >> public void run(){ >> try{ >> System.out.println("Opening >> mic"); // >> AudioInput ai=new AudioInput(t); >> // ai.start(); >> if(t.input==null){ >> AudioFormat format = new >> AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, >> false); >> DataLine.Info targetInfo = new >> DataLine.Info(TargetDataLine.class, format, 44100); >> t.input = (TargetDataLine) >> AudioSystem.getLine(targetInfo); >> >> t.input.open(format,44100); >> System.out.println(" Mic opened"); >> >> t.input.start(); >> System.out.println("Constructing speex encoder."); >> pcm2speex=new Pcm2SpeexAudioInputStream(new >> AudioInputStream(t.input), format, AudioSystem.NOT_SPECIFIED); >> System.out.println("Speex encoder constructed."); >> System.out.println("*** Speex info: "); >> System.out.println("Bitrate: >> "+pcm2speex.getEncoder().getBitRate()); >> System.out.println("Frame size: >> "+pcm2speex.getEncoder().getFrameSize()); >> System.out.println("Complexity: >> "+pcm2speex.getEncoder().getComplexity()); >> System.out.println("Mode: >> "+pcm2speex.getEncoder().getMode()); >> System.out.println("Sampling rate: >> "+pcm2speex.getEncoder().getSamplingRate()); >> System.out.println("relative quality: >> "+pcm2speex.getEncoder().getRelativeQuality()); >> System.out.println("*** end of speex info"); >> System.out.println("everything ok in writer"); >> } byte[] frame=new >> byte[t.framelength]; while(true){ >> int n=pcm2speex.read(frame, 0, frame.length); >> System.out.println(""+n+" bytes read."); >> >> t.recordBuffer.addElement(frame); >> } >> } >> catch(Exception e){ >> e.printStackTrace(); >> } >> } >> >> now all this code does, is sitting and doing nothing after >> 'everything ok in writer' - it simply doesn't read any data, at least >> that's what it looks like, or am i using the class in a wrong >> context? t.framelength is 160 at the moment. > > > not specific enough - i mean Pcm2SpeexAudioInputStream with 'the class' > > > --- >8 ---- > List archives: http://www.xiph.org/archives/ > Ogg project homepage: http://www.xiph.org/ogg/ > To unsubscribe from this list, send a message to > 'speex-dev-request@xiph.org' > containing only the word 'unsubscribe' in the body. No subject is > needed. > Unsubscribe messages sent to the list will be ignored/filtered. > >--- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'speex-dev-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Ulrich B. Staudinger wrote:> Hi, > > i have: > > public void run(){ > try{ > System.out.println("Opening > mic"); // AudioInput > ai=new AudioInput(t); > // ai.start(); > if(t.input==null){ > AudioFormat format = new > AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, > false); > DataLine.Info targetInfo = new > DataLine.Info(TargetDataLine.class, format, 44100); > t.input = (TargetDataLine) > AudioSystem.getLine(targetInfo); > > t.input.open(format,44100); > System.out.println(" Mic opened"); > > t.input.start(); > System.out.println("Constructing speex encoder."); > pcm2speex=new Pcm2SpeexAudioInputStream(new > AudioInputStream(t.input), format, AudioSystem.NOT_SPECIFIED); > System.out.println("Speex encoder constructed."); > System.out.println("*** Speex info: "); > System.out.println("Bitrate: > "+pcm2speex.getEncoder().getBitRate()); > System.out.println("Frame size: > "+pcm2speex.getEncoder().getFrameSize()); > System.out.println("Complexity: > "+pcm2speex.getEncoder().getComplexity()); > System.out.println("Mode: > "+pcm2speex.getEncoder().getMode()); > System.out.println("Sampling rate: > "+pcm2speex.getEncoder().getSamplingRate()); > System.out.println("relative quality: > "+pcm2speex.getEncoder().getRelativeQuality()); > System.out.println("*** end of speex info"); > System.out.println("everything ok in writer"); > } byte[] frame=new > byte[t.framelength]; while(true){ > int n=pcm2speex.read(frame, 0, frame.length); > System.out.println(""+n+" bytes read."); > > t.recordBuffer.addElement(frame); > } > } > catch(Exception e){ > e.printStackTrace(); > } > } > > now all this code does, is sitting and doing nothing after 'everything > ok in writer' - it simply doesn't read any data, at least that's what > it looks like, or am i using the class in a wrong context? > t.framelength is 160 at the moment.not specific enough - i mean Pcm2SpeexAudioInputStream with 'the class' <p>--- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'speex-dev-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Hi Marc, thanks for the quick reply. Marc Gimpel wrote:> It would appear the the 'pcm2speex.read(frame, 0, frame.length)' is > blocking which means that it is waiting for data from the underlying > inputstream (i.e.AudioInputStream(t.input)). If it could read > sufficient data it would transcode it. If it recieved an EOF, it > should do some zero padding and then transcode it. Are you sure that > you are receiving data from the underlying inputstream???Yes, it can recieve data from the underlying input stream. If i read directly from the audioinputstream with auin=new AudioInputStream(t.input); //int n=pcm2speex.read(frame, 0, frame.length); int n=auin.read(frame, 0, frame.length); i can read the specified frame length of bytes repetively. What else could be the cause for blocking? I am really glad about every hint!> One point to note though is that is you are receiving 44kHz audio, > it will try to encode this as UWB (i.e. pretending it's 32kHz sampling > rate), which means that to encode 1 speex packet you are going to need > 640 samples, or 1280 bytes (which should compress down to something > like 29 bytes because the quality setting should be 3 by default).what about piping the input streams? can't i manually read 640 samples from my AudioInputStream (which works) and hand them to a pipe (PipedInputStream connected with an PipedOutputStream) which ends in an InputStream in the Pcm2Speex constructor?> Having said this, jspeex does provide an SPI interface so you > should be able to ask JavaSound to give you directly a a Speex > AudioInputStream. It's coded although I admit that I never got round > to testing it so it might not work. It does work for the decoding, > that I'm sure of in any case.that's interesting ... i have to look into this, but am not really that familiar with SPI ... more with Swing and user interfaces ;-) I attached my TestClient.java, maybe it's of help ... Just press 'join' if you actually start it ... best regards, ulrich -------------- next part -------------- A non-text attachment was scrubbed... Name: TestClient.java Type: text/x-java Size: 14776 bytes Desc: TestClient.java Url : http://lists.xiph.org/pipermail/speex-dev/attachments/20031031/28efc5ae/TestClient-0001.java