5
0

More than 3 years have passed since last update.

10分でHMS Audio Engineを利用してアプリにカラオケ機能を実装

Posted at

カラオケ機能(エコー機能)のアプリを作りました。

早速HMS Audio Engineを使って、シンプルにカラオケ機能(エコー機能)をアプリで作りました。

◆ Object作成、Object初期化、Callbackの登録

mHwAudioKit = new HwAudioKit(this, callBack);
mHwAudioKit.initialize();
// Create KaraokeFeature:
mHwAudioKaraokeFeatureKit = mHwAudioKit.createFeature(HwAudioKit.FeatureType. HWAUDIO_FEATURE_KARAOKE);
// Create a callback task.
IAudioKitCallback callBack = new IAudioKitCallback() {
@Override    
public void onResult(int i) {
        if (i == 0) {
             // HwAudioKit initialization is successful. Its APIs can be used, such as
             mHwAudioKit .getSupportedFeatures(); //Return the list set.
             mHwAudioKit .isFeatureSupported(FeatureType type); // Return true or false: true indicates supported, while false indicates the product does not support the query function.
        }
        if (i == 2) {
            // The Engine service is not installed and the kit is not supported
        }
        if (i == 1000) {
            // HwAudioKit initialization is successful. Its APIs can be used, such as:
            // Query whether Karaoke is supported: true indicates supported, while false indicates not.
            int isSupport = mHwAudioKaraokeFeatureKit.isKaraokeFeatureSupport();
            // Turn on or off the headset monitoring function. The value 0 indicates success, 1806 indicates that the product does not support the karaoke function, and 1805 indicates that no headset is inserted.
            boolean enableSuccess = mHwAudioKaraokeFeatureKit.enableKaraokeFeature(enable);
            // Set the sound effect and volume. The value 0 indicates success, 1806 indicates that the product does not support the karaoke function, 1805 indicates that no headset is inserted, and 1807 indicates parameter error. 
           int success = mHwAudioKaraokeFeatureKit.setParameter(HwAudioKaraokeFeatureKit.ParameName.CMD_SET_AUDIO_EFFECT_MODE_BASE, value);
           // Obtain the latency information.The value -1 indicates obtaining failure
           int latency = mHwAudioKaraokeFeatureKit.getKaraokeLatency();
        }
    }
}

◆ Object廃棄

mHwAudioKaraokeFeatureKit.destroy();
mHwAudioKit.destroy();

完成

audio.PNG

START RECORDING、STOP RECORDING、PLAY RECORDINGで自分の音声を録音して再生。
TURN ON KARAOKEで自分の音声をリアルタイムで聞くことができます(エコー機能)。
さらに、KTVモードやTHEATERモードなども変更可能です。

参考

HMS Audio Engineについて
https://developer.huawei.com/consumer/en/doc/development/Media-Guides/audio-introduction

開発ガイド
https://developer.huawei.com/consumer/en/doc/development/Media-Guides/audio-guide

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0