2012-05-09 19 views
5

का रूपांतरण मुझे डब्ल्यूएवी फ़ाइल के ऑडियो प्रारूप को बदलने में परेशानी हो रही है।ऑडियो प्रारूप

मैं अपने माइक्रोफोन से ध्वनि रिकॉर्डिंग कर रहा हूँ और ध्वनि निम्न स्वरूप में दर्ज की गई है: PCM_SIGNED 44100.0 हर्ट्ज, 16 बिट, मोनो, 2 बाइट्स/फ्रेम

मैं करने के लिए उपरोक्त प्रारूप परिवर्तित करना चाहते हैं, ulaw 8000.0 हर्ट्ज, 8 बिट, मोनो, 1 बाइट/फ्रेम

मैं निम्नलिखित कोड का उपयोग कर रहा,

InputStream is = request.getInputStream(); 
      AudioInputStream ais = AudioSystem.getAudioInputStream(is); 
      AudioFormat oldFormat = ais.getFormat(); 
      AudioFormat newFormat = new AudioFormat(AudioFormat.Encoding.ULAW, 8000, 8, 1, 1, 8000, false) ; 
AudioInputStream lowResAIS = AudioSystem.getAudioInputStream(newFormat, ais); //Getting the below Exception on this line 

और मैं निम्न त्रुटि हो रही है,

java.lang.IllegalArgumentException: असमर्थित रूपांतरण: ulaw 8000.0 हर्ट्ज, 8 बिट, मोनो, 1 बाइट्स/फ्रेम, PCM_SIGNED 44100.0 हर्ट्ज, 16 बिट, मोनो, 2 बाइट्स/फ्रेम, थोड़ा-endian से

कोई कर सकता हूँ कृपया इस समस्या को हल करने में मेरी मदद करें !!!

धन्यवाद एक टन !!!

उत्तर

3

क्या आपने documentation पर एक नज़र डाली?

फेंकता: IllegalArgumentException - यदि रूपांतरण #See #getTargetEncodings (AudioFormat)

हर प्रणाली पर्याप्त कोडेक विशिष्ट प्रारूप आपके द्वारा पूछे गए करने के लिए बदलने के लिए स्थापित किया है जाएगा नहीं समर्थित नहीं है के लिये। आपने अपना मान लिया है, लेकिन यह अपवाद फेंक रहा है क्योंकि यह उस प्रारूप में परिवर्तित नहीं हो सकता है।

आप किसी दिए गए प्रारूप की उपयुक्तता की जांच करने के लिए getTargetEncodings का उपयोग कर सकते हैं, अपवाद पर भरोसा किए बिना, और यदि आप आउटपुट प्रारूप उपलब्ध नहीं हैं तो उचित कार्रवाई कर सकते हैं (उदाहरण के लिए किसी दूसरे पर वापस आना, उपयोगकर्ता को प्रस्तुत करना प्रतिक्रिया के साथ कि यह असंभव है, आदि)।

+0

अरे एंड्रज! उत्तर के लिए धन्यवाद। मैं आंशिक रूप से प्रलेखन के माध्यम से चला गया है। मैंने getTargetEncodings() विधि को निम्न प्रकार 'कोड' एन्कोडिंग [] encArr = AudioSystem.getTargetEncodings (oldFormat) में उपयोग किया; \t \t \t \t के लिए (int i = 0; मैं " + encArr [i]); \t \t \t \t} 'code' और मैं निम्नलिखित उत्पादन मिल गया: 0 -> PCM_SIGNED 1 -> PCM_UNSIGNED 2 -> ALAW 3 -> ulaw, क्या आप इस बारे में क्या कहना है? धन्यवाद!! –

+0

चूंकि मुझे उपरोक्त आउटपुट मिल रहा है, इसलिए मेरे सिस्टम में कोडेक्स को ULAW प्रारूप में बदलने के लिए, मैं अनुमान लगा रहा हूं। अपवाद के लिए दूसरा कारण क्या हो सकता है? कोई उपाय? –

+1

यह रूपांतरण के किसी अन्य पहलू का समर्थन नहीं कर सकता है, जैसे नमूना दर या बिट्स की संख्या। मैं इस पर पूरी तरह से नहीं हूं, लेकिन तथ्य यह है कि आप "डाउनसमलिंग" मेरे लिए एक झंडा उठाते हैं। (44100 से 8000 तक जा रहा है)।यह आमतौर पर मुश्किल है, क्योंकि 4000 और 22050 हर्ट्ज के बीच आवृत्तियों वाली डेटा जानकारी तब तक उपनाम नहीं होगी जब तक कि आप उन्हें डेटा से बाहर फ़िल्टर न करें। तो मेरा अनुमान है कि मानक समर्थित रूपांतरण नहीं है। लेकिन मुझे यकीन है कि आप अपने आउटपुट दिए गए 44100 हर्ट्ज के साथ यूएलडब्ल्यू में परिवर्तित कर सकते हैं। (मेरा सबसे अच्छा अनुमान।) –

0

यह कक्षा आपकी मदद कर सकती है। मैंने पाया here:

package uk.co.mmscomputing.sound; 

import java.io.*; 

public class CompressInputStream extends FilterInputStream{ 

    /* 
    Convert mono PCM byte stream into A-Law u-Law byte stream 

    static AudioFormat alawformat= new AudioFormat(AudioFormat.Encoding.ALAW,8000,8,1,1,8000,false); 
    static AudioFormat ulawformat= new AudioFormat(AudioFormat.Encoding.ULAW,8000,8,1,1,8000,false); 

    PCM 8000.0 Hz, 16 bit, mono, SIGNED, little-endian 
    static AudioFormat pcmformat = new AudioFormat(8000,16,1,true,false); 

    */ 

    static private Compressor alawcompressor=new ALawCompressor(); 
    static private Compressor ulawcompressor=new uLawCompressor(); 

    private Compressor compressor=null; 

    public CompressInputStream(InputStream in, boolean useALaw)throws IOException{ 
    super(in); 
    compressor=(useALaw)?alawcompressor:ulawcompressor; 
    } 

    public int read()throws IOException{ 
    throw new IOException(getClass().getName()+".read() :\n\tDo not support simple read()."); 
    } 

    public int read(byte[] b)throws IOException{ 
    return read(b,0,b.length); 
    } 

    public int read(byte[] b, int off, int len)throws IOException{ 
    int  i,sample; 
    byte[] inb; 

    inb=new byte[len<<1];   // get 16bit PCM data 
    len=in.read(inb); 
    if(len==-1){return -1;}; 

    i=0; 
    while(i<len){ 
     sample = (inb[i++]&0x00FF); 
     sample |= (inb[i++]<<8); 
     b[off++]=(byte)compressor.compress((short)sample); 
    } 
    return len>>1; 
    } 
} 

abstract class Compressor{ 
    protected abstract int compress(short sample);  
} 

/* 
    Mathematical Tools in Signal Processing with C++ and Java Simulations 
     by Willi-Hans Steeb 
      International School for Scientific Computing 
*/ 

class ALawCompressor extends Compressor{ 

    static final int cClip = 32635; 

    static final int[] ALawCompressTable ={ 
    1,1,2,2,3,3,3,3, 
    4,4,4,4,4,4,4,4, 
    5,5,5,5,5,5,5,5, 
    5,5,5,5,5,5,5,5, 
    6,6,6,6,6,6,6,6, 
    6,6,6,6,6,6,6,6, 
    6,6,6,6,6,6,6,6, 
    6,6,6,6,6,6,6,6, 
    7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7 
    }; 

    protected int compress(short sample){ 
    int sign; 
    int exponent; 
    int mantissa; 
    int compressedByte; 

    sign = ((~sample) >> 8) & 0x80; 
    if(sign==0){ sample *= -1;} 
    if(sample > cClip){ sample = cClip; } 
    if(sample >= 256){ 
     exponent = ALawCompressTable[(sample >> 8) & 0x007F]; 
     mantissa = (sample >> (exponent + 3)) & 0x0F; 
     compressedByte = 0x007F & ((exponent << 4) | mantissa); 
    }else{ 
     compressedByte = 0x007F & (sample >> 4); 
    } 
    compressedByte ^= (sign^0x55); 
    return compressedByte; 
    } 
} 

class uLawCompressor extends Compressor{ 

    static final int cClip = 32635; 
    static final int cBias = 0x84; 

    int[] uLawCompressTable ={ 
    0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3, 
    4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 
    5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 
    5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 
    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 
    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 
    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 
    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 
    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 
    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 
    }; 

    protected int compress(short sample){ 
    int sign; 
    int exponent; 
    int mantissa; 
    int compressedByte; 

    sign = (sample >> 8) & 0x80; 
    if(sign!=0){ sample *= -1;} 
    if(sample > cClip){ sample = cClip; } 
    sample += cBias; 

    exponent = uLawCompressTable[(sample >> 7) & 0x00FF]; 
    mantissa = (sample >> (exponent + 3)) & 0x0F; 
    compressedByte = ~(sign | (exponent << 4) | mantissa); 
    return compressedByte&0x000000FF; 
    } 
} 
+0

वह क्या करता है? क्या यह मुझे निम्न त्रुटि से मदद करेगा? 'प्रारूप पीसीएम_SIGNED 44100.0 हर्ट्ज, 16 बिट, मोनो, 2 बाइट्स/फ्रेम के साथ लाइन, थोड़ा-एंडियन समर्थित नहीं है' – trusktr

+0

मैंने इसका उपयोग नहीं किया है, लेकिन यह "मोनो पीसीएम बाइट स्ट्रीम को ए-लॉ यू-लॉ बाइट स्ट्रीम में परिवर्तित करने का दावा करता है । " ऐसा लगता है कि आप क्या करने की कोशिश कर रहे हैं। ऐसा लगता है कि यह रूपांतरण जावा में सीधे समर्थित नहीं है, आपको अपना स्वयं का संपीड़न करना है (जैसा कि यह वर्ग करता है)। – 11101101b

+1

मेरी त्रुटि को चालू करता है क्योंकि मैं पहले से उपयोग की जा रही डेटा लाइन का उपयोग नहीं कर सका (इसलिए त्रुटि भ्रामक है)। मोती ध्वनि पुस्तकालय का उपयोग करके मेरी सभी समस्याओं का हल (http://beadsproject.net)। – trusktr

संबंधित मुद्दे