From 24c924f57ee3a5295e4efbfe61e1c810f62b86a3 Mon Sep 17 00:00:00 2001 From: junjiejiangjjj Date: Fri, 11 Mar 2022 10:54:10 +0800 Subject: [PATCH] update --- .gitattributes | 35 ++++++++ .gitignore | 209 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 38 ++++++++- __init__.py | 0 audio_decoder.py | 32 +++++++ audio_decoder.yaml | 11 +++ requirements.txt | 1 + 7 files changed, 324 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 __init__.py create mode 100644 audio_decoder.py create mode 100644 audio_decoder.yaml create mode 100644 requirements.txt diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..ab2832a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,35 @@ +# .gitattributes + +# Source files +# ============ +*.pxd text diff=python +*.py text diff=python +*.py3 text diff=python +*.pyw text diff=python +*.pyx text diff=python +*.pyz text diff=python +*.pyi text diff=python + +# Binary files +# ============ +*.db binary +*.p binary +*.pkl binary +*.pickle binary +*.pyc binary export-ignore +*.pyo binary export-ignore +*.pyd binary + +# Jupyter notebook +*.ipynb text + +# Model files +*.bin.* filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tar.gz filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32030ff --- /dev/null +++ b/.gitignore @@ -0,0 +1,209 @@ +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### OSX ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk \ No newline at end of file diff --git a/README.md b/README.md index b978d02..ce55cc6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,37 @@ -# audio-decoder +# Operator: audio-decoder + +Author: + +## Overview + + + +## Interface + +```python +__init__(self) +``` + +```python +__call__(self, audio_path: str) +``` + +Args: + +- audio_path + +Returns: + - audio frame: ndarray + - sample_rate: int + - timestamp: int + +## Requirements +av + + +## How it works + + + +## Reference -2 \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/audio_decoder.py b/audio_decoder.py new file mode 100644 index 0000000..ce6be33 --- /dev/null +++ b/audio_decoder.py @@ -0,0 +1,32 @@ +from typing import Generator, NamedTuple + +import av + +from towhee.operator.base import Operator + +AudioOutput = NamedTuple("Outputs", [("audio_frame", 'ndarray'), ('simple_rate', 'int'), ("TIMESTAMP", 'int')]) + + +class AudioDecoder(Operator): + """ + """ + + def __init__(self) -> None: + super().__init__() + + def __call__(self, audio_path: str): + in_container = av.open(audio_path) + stream = in_container.streams.get(audio=0)[0] + for frame in in_container.decode(stream): + timestamp = frame.time * 1000 + sample_rate = frame.sample_rate + ndarray = frame.to_ndarray() + yield AudioOutput(ndarray, sample_rate, timestamp) + + +if __name__ == '__main__': + d = AudioDecoder() + audio_path = '/Users/jiangjunjie/WorkSpace/audio_data/stereo.wav' + it = d(audio_path) + for data in it: + print(data._asdict()) diff --git a/audio_decoder.yaml b/audio_decoder.yaml new file mode 100644 index 0000000..aca6246 --- /dev/null +++ b/audio_decoder.yaml @@ -0,0 +1,11 @@ +name: 'audio-decoder' +labels: +operator: 'towhee/audio-decoder' +init: +call: + input: + audio_path: str + output: + audio_frame: ndarray + sample_rate: int + timestamp: int diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dc1ce6e --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +av