Skip to content

Instantly share code, notes, and snippets.

View Mirochiu's full-sized avatar

Chiu, Yung-Hsiang Mirochiu

View GitHub Profile
@Mirochiu
Mirochiu / AnyToMP3.cmd
Created October 12, 2019 13:31
take ffmpeg to convert any media file to mp3 with 128kbps in windows batch
cls
@echo off
set in_file=%1
echo in_file=%in_file%
set out_file=%~dpn1.mp3
echo out_file=%out_file%
ffmpeg.exe -i %in_file% -b:a 128K -vn "%out_file%"
@Mirochiu
Mirochiu / gist:eb09c4d087841603d3db6dbf0552af32
Last active July 20, 2019 03:50
Use STT api in CHT IoT platform
#!/bin/bash
## settings
CHT_IOT_STT_API_KEY=aaaaaaaa-bbbb-cccc-dddd-123456789ab
PCM_FILE_FOR_STT=test.pcm
## script start
if [ ! -f "${PCM_FILE_FOR_STT}" ]; then
echo "ERROR:Cannot open pcm file @ ${PCM_FILE_FOR_STT}"
exit 1
fi
@Mirochiu
Mirochiu / gist:3886407801f9bdd9d36c65b9730ae7b8
Created January 20, 2019 02:07
create audio focus request
public AudioFocusHelper(@NonNull Handler handler, int audioFocus) {
mAudioFocus = audioFocus;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.v(TAG, "System is above oreo");
mAudioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
.build();
mFocusRequest = new AudioFocusRequest.Builder(mAudioFocus)
.setAudioAttributes(mAudioAttributes)
@Mirochiu
Mirochiu / playMusicInAssets.java
Created December 4, 2018 03:39
Play a music file in assets for Android App
String assetPath = "{the file name you want fom the asset directory}";
AssetManager asset = getApplication().getApplicationContext().getAssets();
FileDescriptor fd = asset.openFd(assetPath).getFileDescriptor();
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(fd);
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
Log.v(TAG, "[MUSIC] started");
mp.start();
ListForRead = 'C:\Users\User\Desktop\filelist.txt';
fid = fopen(ListForRead,'r');
if fid==-1
error(['cannot open the list=' ListForRead]);
end
DirForSave = 'donwload';
private void showAlertDialog(String msg) {
final String m = msg;
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getContext());
alertDialog.setTitle("Alert");
alertDialog.setMessage(m);
alertDialog.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
@Mirochiu
Mirochiu / TestProxy.java
Created December 22, 2017 05:52
Sample code for implementing the reflection interface
import java.lang.reflect.*;
public class TestProxy {
interface MyListener {
void callback(Object event);
}
static class MyClass implements Runnable {
private String id;
private MyListener l = null;
private Object lock = new Object();