Last active
November 3, 2022 14:21
-
-
Save dkurt/f579b85665f86b1ce1b121ecd0793523 to your computer and use it in GitHub Desktop.
Audio Recognition on Android article: https://medium.com/@dmitry.kurtaev/audio-recognition-in-android-with-openvino-5d51e71f1426
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repositories { | |
mavenCentral() | |
def github = ivy { | |
url "https://github.com/" | |
patternLayout { | |
artifact '/[organisation]/[module]/releases/download/[revision]/openvino-[revision]-[classifier].[ext]' | |
} | |
metadataSources { artifact() } | |
} | |
exclusiveContent { | |
forRepositories(github) | |
filter { includeGroup("dkurt") } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InputStream in = Core.class.getClassLoader().getResourceAsStream("plugins.xml"); | |
String pluginsXml = ""; | |
try { | |
Path path = Files.createTempFile("plugins", "xml"); | |
Files.copy(in, path, StandardCopyOption.REPLACE_EXISTING); | |
pluginsXml = path.toString(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
Core core = new Core(pluginsXml); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
implementation "dkurt:openvino_java:2022.2:android-arm64-v8a@aar" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InferRequest ireq = compiledModel.create_infer_request(); | |
Tensor input = new Tensor(new int[]{1, 16000}, audioData); | |
ireq.set_input_tensor(input); | |
ireq.infer(); | |
Tensor output = ireq.get_output_tensor(); | |
float[] outputData = output.data(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.intel.openvino.*; | |
System.loadLibrary(Core.NATIVE_LIBRARY_NAME); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Model model = core.read_model(modelXml, modelBin); | |
CompiledModel compiledModel = core.compile_model(model, "CPU"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AudioRecord recorder = new AudioRecord( | |
MediaRecorder.AudioSource.MIC, | |
16000, | |
AudioFormat.CHANNEL_IN_MONO, | |
AudioFormat.ENCODING_PCM_FLOAT, | |
16000 * 4 | |
); | |
recorder.startRecording(); | |
float[] audioData = new float[16000]; | |
recorder.read(audioData, 0, 16000, AudioRecord.READ_BLOCKING); | |
recorder.stop(); | |
recorder.release(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment