Skip to content

Instantly share code, notes, and snippets.

View weihanchen's full-sized avatar
🏁

weihanchen weihanchen

🏁
  • Taiwan
View GitHub Profile
# |- <套件包名稱>
# |- core.py
from typing import List
def sum_array(arr: List[int]) -> int:
"""陣列總和器
Args:
arr (List[int]): 整數陣列元素
def try_except_finally_example():
try:
num1 = int(input("請輸入一個整數: "))
num2 = int(input("請輸入另一個整數: "))
result = num1 / num2
except ZeroDivisionError:
print("錯誤:除以零。")
except ValueError:
print("錯誤:輸入的不是整數。")
finally:
def try_except_else_example():
try:
num1 = int(input("請輸入一個整數: "))
num2 = int(input("請輸入另一個整數: "))
result = num1 / num2
except ZeroDivisionError:
print("錯誤:除以零。")
except ValueError:
print("錯誤:輸入的不是整數。")
else:
def raise_example(num: int):
try:
if num <= 10:
raise ValueError(f"{num} 必須大於10")
except ValueError as e:
print(e)
raise
raise_example(9)
@weihanchen
weihanchen / decode_audio.py
Created May 9, 2023 22:54
pydub音訊處理: 分離左右聲道並轉換成Numpy Array結構,以進行whisper語音辨識
import io
from typing import BinaryIO, Tuple, Union
import numpy as np
from pydub.utils import get_array_type
def decode_audio(
input_file: Union[str, BinaryIO],
sampling_rate: int = 16000,
) -> Tuple[np.ndarray, np.ndarray]:
@weihanchen
weihanchen / retry.go
Created December 31, 2020 02:58
Go Retry Policy
func retry(maxRetryCount int, retryPeriod int, job func() error) error {
for retryCount := 1; ; retryCount++ {
err := job()
if err == nil {
return nil
}
// 進入retry模式
if retryCount <= maxRetryCount {
glog.Errorf("error: %s, retry: %d, max: %d, wait: %ds", err, retryCount, maxRetryCount, retryPeriod)
time.Sleep(time.Second * time.Duration(retryPeriod))
@weihanchen
weihanchen / data_utils.py
Last active January 7, 2019 03:05
sequence_tagging
# -*- coding: UTF-8 -*-
import numpy as np
import os
import codecs
# shared global variables to be imported from model also
UNK = "$UNK$"
NUM = "$NUM$"
NONE = "O"
<?php
$options = array(
1 => 'Opt1',
2 => 'Opt2',
3 => 'Opt3',
);
?>
const portAudio = require('naudiodon');
const fs = require('fs');
const wav = require('wav');
const request = require('request');
const ai = new portAudio.AudioInput({
channelCount: 1,
sampleFormat: portAudio.SampleFormat16Bit,
sampleRate: 8000,
git tag -d 0.1.0
git tag 0.1.0
git push origin 0.1.0