###前提・実現したいこと
Android Studioで楽曲のボーカルカットをするアプリを作っています。
ボーカルカット部分のプログラムはあらかじめeclipseで作成しWindows上で正常に動作していたのですが、Android Studioの方に貼り付けた際に
「エラー: パッケージjavax.sound.sampledは存在しません」
と表示され、利用することができません。
なんとかAndroidでJava Sound APIを利用する方法はないのでしょうか?
###発生している問題・エラーメッセージ
エラー :(14, 27) エラー: パッケージjavax.sound.sampledは存在しません エラー :(24, 13) エラー: シンボルを見つけられません シンボル: クラス AudioInputStream 場所: クラス WavVocalCut エラー :(24, 36) エラー: シンボルを見つけられません シンボル: 変数 AudioSystem 場所: クラス WavVocalCut エラー :(33, 13) エラー: シンボルを見つけられません シンボル: クラス AudioFormat 場所: クラス WavVocalCut エラー :Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details.
###該当のソースコード
Java
1package jp.kaken.musicplayer; 2 3import android.content.Context; 4import android.net.Uri; 5import android.os.Environment; 6import android.widget.Toast; 7 8import java.io.ByteArrayInputStream; 9import java.io.File; 10 11import javax.sound.sampled.AudioFileFormat; 12import javax.sound.sampled.AudioFormat; 13import javax.sound.sampled.AudioInputStream; 14import javax.sound.sampled.AudioSystem; 15 16public class WavVocalCut { 17 public static void wavVocalCut(Context context, Uri inputUri, String fileName){ 18 Toast.makeText(context,"start",Toast.LENGTH_SHORT); 19 try { 20 File inputFile = new File(inputUri.toString()); 21 AudioInputStream ais = AudioSystem.getAudioInputStream(inputFile); 22 // オーディオ入力ストリームからデータを読む 23 byte[] data1 = new byte[ais.available()]; 24 short[] data2 = new short[ais.available() / 2]; 25 short[] vcdata = new short[ais.available()/4]; 26 byte[] data3 = new byte[ais.available()/2]; 27 ais.read(data1); 28 ais.close(); 29 // ファイルのフォーマットを調べる 30 AudioFormat af = ais.getFormat(); 31 boolean isPcmSigned=(af.getEncoding()==AudioFormat.Encoding.PCM_SIGNED); 32 if(af.getChannels()==2 && 33 af.getSampleSizeInBits()==16 && 34 !isPcmSigned 35 ){ 36 for(int i=0,j=0;i<data1.length;i+=2,j++){ 37 data3[j]=(byte)((data1[i]-data1[i+1])/2+128); 38 } 39 }else if (af.getChannels() == 2 && 40 af.getSampleSizeInBits() == 16 && 41 isPcmSigned && 42 (!af.isBigEndian())) { // ステレオ,16ビット,符号付PCM,リトルエンディアン 43 //ステレオ16ビットのためbyte->short変換を一旦行う 44 for (int i = 0, j = 0, k = 0; i < data1.length; i += 4, j += 2, k++) { 45 data2[j]=(short)((data1[i] & 0xff) | ((data1[i+1] << 8) & 0xff00)); 46 data2[j+1]=(short)((data1[i+2] & 0xff) | ((data1[i+3] << 8) & 0xff00)); 47 vcdata[k]=(short) ((data2[j]-data2[j+1])/2); 48 } 49 //short->byte変換 50 for(int i=0,j=0;i<data2.length;i+=2,j++){ 51 data3[i]=(byte) ((vcdata[j])); 52 data3[i+1]=(byte) (vcdata[j]>>8); 53 } 54 55 } 56 57 AudioFormat aof = new AudioFormat(af.getSampleRate(), af.getSampleSizeInBits(), 1, true, 58 false); 59 AudioInputStream aos = new AudioInputStream( 60 new ByteArrayInputStream(data3) 61 , aof 62 , data3.length / 2); 63 String folder = Environment.getExternalStorageDirectory().toString() + "/VCdata"; 64 File outputFile = new File(folder + "/" + fileName + " vc"); 65 AudioSystem.write(aos, AudioFileFormat.Type.WAVE, outputFile); 66 aos.close(); 67 Toast.makeText(context,"成功",Toast.LENGTH_SHORT); 68 } catch (Exception e) { 69 e.printStackTrace(); 70 Toast.makeText(context,"失敗",Toast.LENGTH_SHORT); 71 } 72 } 73 } 74 75
###試したこと
libsに
「tritonus-share-0.3.7-1.jar」(http://www.java2s.com/Code/Jar/t/Downloadtritonusshare0371jar.htm)
を入れる
###結果
エラー :This is often due to inadvertently including a core library file
エラー :However, you might actually be trying to define a class in a core
エラー :If you really intend to build a core library -- which is only
エラー :trouble processing "javax/sound/midi/ControllerEventListener.class":
エラー :appropriate as part of creating a full virtual machine
エラー :It is also often of questionable legality.
エラー :core class, then this is the most likely explanation of what's
エラー :namespace, the source of which you may have taken, for example,
エラー :assuredly not work. At a minimum, it jeopardizes the
エラー :Eclipse). If you are sure you're not intentionally defining a
エラー :compatibility of your app with future versions of the platform.
エラー :going on.
エラー :when not building a core library.
エラー :in your application's project, when using an IDE (such as
エラー :from a non-Android virtual machine project. This will most
エラー :Ill-advised or mistaken usage of a core class (java.* or javax.*)
エラー :the "--core-library" option to suppress this error message.
エラー :distribution, as opposed to compiling an application -- then use
エラー :If you go ahead and use "--core-library" but are in fact
エラー :building an application, then be forewarned that your application
エラー :will still fail to build or run, at some point. Please be
エラー :prepared for angry customers who find, for example, that your
エラー :application ceases to function once they upgrade their operating
エラー :system. You will be to blame for this problem.
エラー :If you are legitimately using some code that happens to be in a
エラー :core package, then the easiest safe alternative you have is to
エラー :your own package namespace. This means that they will never be in
エラー :repackage that code. That is, move the classes in question into
エラー :conflict with core system classes. JarJar is a tool that may help
エラー :you in this endeavor. If you find that you cannot do this, then
エラー :that is an indication that the path you are on will ultimately
エラー :lead to pain, suffering, grief, and lamentation.
エラー :1 error; aborting
エラー :Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process
と出る
###補足情報(言語/FW/ツール等のバージョンなど)
Android Studio 2.3.3
Java
あなたの回答
tips
プレビュー