Spaces:
Running
Running
tjysdsg
commited on
Commit
•
55bf388
0
Parent(s):
initial commit
Browse files- .gitattributes +35 -0
- .gitignore +370 -0
- README.md +13 -0
- app.py +109 -0
- output.wav +0 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,370 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
data
|
2 |
+
|
3 |
+
# Created by https://www.toptal.com/developers/gitignore/api/linux,windows,macos,jetbrains+all,visualstudiocode,python,jupyternotebooks
|
4 |
+
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,windows,macos,jetbrains+all,visualstudiocode,python,jupyternotebooks
|
5 |
+
|
6 |
+
### JetBrains+all ###
|
7 |
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
8 |
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
9 |
+
|
10 |
+
# User-specific stuff
|
11 |
+
.idea/**/workspace.xml
|
12 |
+
.idea/**/tasks.xml
|
13 |
+
.idea/**/usage.statistics.xml
|
14 |
+
.idea/**/dictionaries
|
15 |
+
.idea/**/shelf
|
16 |
+
|
17 |
+
# AWS User-specific
|
18 |
+
.idea/**/aws.xml
|
19 |
+
|
20 |
+
# Generated files
|
21 |
+
.idea/**/contentModel.xml
|
22 |
+
|
23 |
+
# Sensitive or high-churn files
|
24 |
+
.idea/**/dataSources/
|
25 |
+
.idea/**/dataSources.ids
|
26 |
+
.idea/**/dataSources.local.xml
|
27 |
+
.idea/**/sqlDataSources.xml
|
28 |
+
.idea/**/dynamic.xml
|
29 |
+
.idea/**/uiDesigner.xml
|
30 |
+
.idea/**/dbnavigator.xml
|
31 |
+
|
32 |
+
# Gradle
|
33 |
+
.idea/**/gradle.xml
|
34 |
+
.idea/**/libraries
|
35 |
+
|
36 |
+
# Gradle and Maven with auto-import
|
37 |
+
# When using Gradle or Maven with auto-import, you should exclude module files,
|
38 |
+
# since they will be recreated, and may cause churn. Uncomment if using
|
39 |
+
# auto-import.
|
40 |
+
# .idea/artifacts
|
41 |
+
# .idea/compiler.xml
|
42 |
+
# .idea/jarRepositories.xml
|
43 |
+
# .idea/modules.xml
|
44 |
+
# .idea/*.iml
|
45 |
+
# .idea/modules
|
46 |
+
# *.iml
|
47 |
+
# *.ipr
|
48 |
+
|
49 |
+
# CMake
|
50 |
+
cmake-build-*/
|
51 |
+
|
52 |
+
# Mongo Explorer plugin
|
53 |
+
.idea/**/mongoSettings.xml
|
54 |
+
|
55 |
+
# File-based project format
|
56 |
+
*.iws
|
57 |
+
|
58 |
+
# IntelliJ
|
59 |
+
out/
|
60 |
+
|
61 |
+
# mpeltonen/sbt-idea plugin
|
62 |
+
.idea_modules/
|
63 |
+
|
64 |
+
# JIRA plugin
|
65 |
+
atlassian-ide-plugin.xml
|
66 |
+
|
67 |
+
# Cursive Clojure plugin
|
68 |
+
.idea/replstate.xml
|
69 |
+
|
70 |
+
# SonarLint plugin
|
71 |
+
.idea/sonarlint/
|
72 |
+
|
73 |
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
74 |
+
com_crashlytics_export_strings.xml
|
75 |
+
crashlytics.properties
|
76 |
+
crashlytics-build.properties
|
77 |
+
fabric.properties
|
78 |
+
|
79 |
+
# Editor-based Rest Client
|
80 |
+
.idea/httpRequests
|
81 |
+
|
82 |
+
# Android studio 3.1+ serialized cache file
|
83 |
+
.idea/caches/build_file_checksums.ser
|
84 |
+
|
85 |
+
### JetBrains+all Patch ###
|
86 |
+
# Ignore everything but code style settings and run configurations
|
87 |
+
# that are supposed to be shared within teams.
|
88 |
+
|
89 |
+
.idea/*
|
90 |
+
|
91 |
+
!.idea/codeStyles
|
92 |
+
!.idea/runConfigurations
|
93 |
+
|
94 |
+
### JupyterNotebooks ###
|
95 |
+
# gitignore template for Jupyter Notebooks
|
96 |
+
# website: http://jupyter.org/
|
97 |
+
|
98 |
+
.ipynb_checkpoints
|
99 |
+
*/.ipynb_checkpoints/*
|
100 |
+
|
101 |
+
# IPython
|
102 |
+
profile_default/
|
103 |
+
ipython_config.py
|
104 |
+
|
105 |
+
# Remove previous ipynb_checkpoints
|
106 |
+
# git rm -r .ipynb_checkpoints/
|
107 |
+
|
108 |
+
### Linux ###
|
109 |
+
*~
|
110 |
+
|
111 |
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
112 |
+
.fuse_hidden*
|
113 |
+
|
114 |
+
# KDE directory preferences
|
115 |
+
.directory
|
116 |
+
|
117 |
+
# Linux trash folder which might appear on any partition or disk
|
118 |
+
.Trash-*
|
119 |
+
|
120 |
+
# .nfs files are created when an open file is removed but is still being accessed
|
121 |
+
.nfs*
|
122 |
+
|
123 |
+
### macOS ###
|
124 |
+
# General
|
125 |
+
.DS_Store
|
126 |
+
.AppleDouble
|
127 |
+
.LSOverride
|
128 |
+
|
129 |
+
# Icon must end with two \r
|
130 |
+
Icon
|
131 |
+
|
132 |
+
|
133 |
+
# Thumbnails
|
134 |
+
._*
|
135 |
+
|
136 |
+
# Files that might appear in the root of a volume
|
137 |
+
.DocumentRevisions-V100
|
138 |
+
.fseventsd
|
139 |
+
.Spotlight-V100
|
140 |
+
.TemporaryItems
|
141 |
+
.Trashes
|
142 |
+
.VolumeIcon.icns
|
143 |
+
.com.apple.timemachine.donotpresent
|
144 |
+
|
145 |
+
# Directories potentially created on remote AFP share
|
146 |
+
.AppleDB
|
147 |
+
.AppleDesktop
|
148 |
+
Network Trash Folder
|
149 |
+
Temporary Items
|
150 |
+
.apdisk
|
151 |
+
|
152 |
+
### macOS Patch ###
|
153 |
+
# iCloud generated files
|
154 |
+
*.icloud
|
155 |
+
|
156 |
+
### Python ###
|
157 |
+
# Byte-compiled / optimized / DLL files
|
158 |
+
__pycache__/
|
159 |
+
*.py[cod]
|
160 |
+
*$py.class
|
161 |
+
|
162 |
+
# C extensions
|
163 |
+
*.so
|
164 |
+
|
165 |
+
# Distribution / packaging
|
166 |
+
.Python
|
167 |
+
build/
|
168 |
+
develop-eggs/
|
169 |
+
dist/
|
170 |
+
downloads/
|
171 |
+
eggs/
|
172 |
+
.eggs/
|
173 |
+
lib/
|
174 |
+
lib64/
|
175 |
+
parts/
|
176 |
+
sdist/
|
177 |
+
var/
|
178 |
+
wheels/
|
179 |
+
share/python-wheels/
|
180 |
+
*.egg-info/
|
181 |
+
.installed.cfg
|
182 |
+
*.egg
|
183 |
+
MANIFEST
|
184 |
+
|
185 |
+
# PyInstaller
|
186 |
+
# Usually these files are written by a python script from a template
|
187 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
188 |
+
*.manifest
|
189 |
+
*.spec
|
190 |
+
|
191 |
+
# Installer logs
|
192 |
+
pip-log.txt
|
193 |
+
pip-delete-this-directory.txt
|
194 |
+
|
195 |
+
# Unit test / coverage reports
|
196 |
+
htmlcov/
|
197 |
+
.tox/
|
198 |
+
.nox/
|
199 |
+
.coverage
|
200 |
+
.coverage.*
|
201 |
+
.cache
|
202 |
+
nosetests.xml
|
203 |
+
coverage.xml
|
204 |
+
*.cover
|
205 |
+
*.py,cover
|
206 |
+
.hypothesis/
|
207 |
+
.pytest_cache/
|
208 |
+
cover/
|
209 |
+
|
210 |
+
# Translations
|
211 |
+
*.mo
|
212 |
+
*.pot
|
213 |
+
|
214 |
+
# Django stuff:
|
215 |
+
*.log
|
216 |
+
local_settings.py
|
217 |
+
db.sqlite3
|
218 |
+
db.sqlite3-journal
|
219 |
+
|
220 |
+
# Flask stuff:
|
221 |
+
instance/
|
222 |
+
.webassets-cache
|
223 |
+
|
224 |
+
# Scrapy stuff:
|
225 |
+
.scrapy
|
226 |
+
|
227 |
+
# Sphinx documentation
|
228 |
+
docs/_build/
|
229 |
+
|
230 |
+
# PyBuilder
|
231 |
+
.pybuilder/
|
232 |
+
target/
|
233 |
+
|
234 |
+
# Jupyter Notebook
|
235 |
+
|
236 |
+
# IPython
|
237 |
+
|
238 |
+
# pyenv
|
239 |
+
# For a library or package, you might want to ignore these files since the code is
|
240 |
+
# intended to run in multiple environments; otherwise, check them in:
|
241 |
+
# .python-version
|
242 |
+
|
243 |
+
# pipenv
|
244 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
245 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
246 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
247 |
+
# install all needed dependencies.
|
248 |
+
#Pipfile.lock
|
249 |
+
|
250 |
+
# poetry
|
251 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
252 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
253 |
+
# commonly ignored for libraries.
|
254 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
255 |
+
#poetry.lock
|
256 |
+
|
257 |
+
# pdm
|
258 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
259 |
+
#pdm.lock
|
260 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
261 |
+
# in version control.
|
262 |
+
# https://pdm.fming.dev/#use-with-ide
|
263 |
+
.pdm.toml
|
264 |
+
|
265 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
266 |
+
__pypackages__/
|
267 |
+
|
268 |
+
# Celery stuff
|
269 |
+
celerybeat-schedule
|
270 |
+
celerybeat.pid
|
271 |
+
|
272 |
+
# SageMath parsed files
|
273 |
+
*.sage.py
|
274 |
+
|
275 |
+
# Environments
|
276 |
+
.env
|
277 |
+
.venv
|
278 |
+
env/
|
279 |
+
venv/
|
280 |
+
ENV/
|
281 |
+
env.bak/
|
282 |
+
venv.bak/
|
283 |
+
|
284 |
+
# Spyder project settings
|
285 |
+
.spyderproject
|
286 |
+
.spyproject
|
287 |
+
|
288 |
+
# Rope project settings
|
289 |
+
.ropeproject
|
290 |
+
|
291 |
+
# mkdocs documentation
|
292 |
+
/site
|
293 |
+
|
294 |
+
# mypy
|
295 |
+
.mypy_cache/
|
296 |
+
.dmypy.json
|
297 |
+
dmypy.json
|
298 |
+
|
299 |
+
# Pyre type checker
|
300 |
+
.pyre/
|
301 |
+
|
302 |
+
# pytype static type analyzer
|
303 |
+
.pytype/
|
304 |
+
|
305 |
+
# Cython debug symbols
|
306 |
+
cython_debug/
|
307 |
+
|
308 |
+
# PyCharm
|
309 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
310 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
311 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
312 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
313 |
+
#.idea/
|
314 |
+
|
315 |
+
### Python Patch ###
|
316 |
+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
317 |
+
poetry.toml
|
318 |
+
|
319 |
+
# ruff
|
320 |
+
.ruff_cache/
|
321 |
+
|
322 |
+
# LSP config files
|
323 |
+
pyrightconfig.json
|
324 |
+
|
325 |
+
### VisualStudioCode ###
|
326 |
+
.vscode/*
|
327 |
+
!.vscode/settings.json
|
328 |
+
!.vscode/tasks.json
|
329 |
+
!.vscode/launch.json
|
330 |
+
!.vscode/extensions.json
|
331 |
+
!.vscode/*.code-snippets
|
332 |
+
|
333 |
+
# Local History for Visual Studio Code
|
334 |
+
.history/
|
335 |
+
|
336 |
+
# Built Visual Studio Code Extensions
|
337 |
+
*.vsix
|
338 |
+
|
339 |
+
### VisualStudioCode Patch ###
|
340 |
+
# Ignore all local history of files
|
341 |
+
.history
|
342 |
+
.ionide
|
343 |
+
|
344 |
+
### Windows ###
|
345 |
+
# Windows thumbnail cache files
|
346 |
+
Thumbs.db
|
347 |
+
Thumbs.db:encryptable
|
348 |
+
ehthumbs.db
|
349 |
+
ehthumbs_vista.db
|
350 |
+
|
351 |
+
# Dump file
|
352 |
+
*.stackdump
|
353 |
+
|
354 |
+
# Folder config file
|
355 |
+
[Dd]esktop.ini
|
356 |
+
|
357 |
+
# Recycle Bin used on file shares
|
358 |
+
$RECYCLE.BIN/
|
359 |
+
|
360 |
+
# Windows Installer files
|
361 |
+
*.cab
|
362 |
+
*.msi
|
363 |
+
*.msix
|
364 |
+
*.msm
|
365 |
+
*.msp
|
366 |
+
|
367 |
+
# Windows shortcuts
|
368 |
+
*.lnk
|
369 |
+
|
370 |
+
# End of https://www.toptal.com/developers/gitignore/api/linux,windows,macos,jetbrains+all,visualstudiocode,python,jupyternotebooks
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: S2st
|
3 |
+
emoji: 📉
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.47.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
import torch
|
5 |
+
import torchaudio
|
6 |
+
from typing import Tuple, Optional
|
7 |
+
|
8 |
+
SAMPLE_RATE = 16000
|
9 |
+
MAX_INPUT_LENGTH = 60 # seconds
|
10 |
+
|
11 |
+
|
12 |
+
def s2st(
|
13 |
+
audio_source: str,
|
14 |
+
input_audio_mic: Optional[str],
|
15 |
+
input_audio_file: Optional[str],
|
16 |
+
):
|
17 |
+
if audio_source == 'file':
|
18 |
+
input_path = input_audio_file
|
19 |
+
else:
|
20 |
+
input_path = input_audio_mic
|
21 |
+
|
22 |
+
if input_path is None:
|
23 |
+
gr.Error(f"Input audio is too long. Truncated to {MAX_INPUT_LENGTH} seconds.")
|
24 |
+
return (None, None), None
|
25 |
+
|
26 |
+
orig_wav, orig_sr = torchaudio.load(input_path)
|
27 |
+
wav = torchaudio.functional.resample(orig_wav, orig_freq=orig_sr, new_freq=SAMPLE_RATE)
|
28 |
+
max_length = int(MAX_INPUT_LENGTH * SAMPLE_RATE)
|
29 |
+
if wav.shape[1] > max_length:
|
30 |
+
wav = wav[:, :max_length]
|
31 |
+
gr.Warning(f"Input audio is too long. Truncated to {MAX_INPUT_LENGTH} seconds.")
|
32 |
+
|
33 |
+
wav = wav[0] # mono
|
34 |
+
|
35 |
+
# TODO: translate wav
|
36 |
+
output_path = 'output.wav'
|
37 |
+
torchaudio.save(output_path, wav.unsqueeze(0), SAMPLE_RATE)
|
38 |
+
|
39 |
+
return output_path, f'Source: {audio_source}'
|
40 |
+
|
41 |
+
|
42 |
+
def update_audio_ui(audio_source: str) -> Tuple[dict, dict]:
|
43 |
+
mic = audio_source == "microphone"
|
44 |
+
return (
|
45 |
+
gr.update(visible=mic, value=None), # input_audio_mic
|
46 |
+
gr.update(visible=not mic, value=None), # input_audio_file
|
47 |
+
)
|
48 |
+
|
49 |
+
|
50 |
+
def main():
|
51 |
+
with gr.Blocks() as demo:
|
52 |
+
with gr.Group():
|
53 |
+
with gr.Row() as audio_box:
|
54 |
+
audio_source = gr.Radio(
|
55 |
+
label="Audio source",
|
56 |
+
choices=["file", "microphone"],
|
57 |
+
value="file",
|
58 |
+
)
|
59 |
+
input_audio_mic = gr.Audio(
|
60 |
+
label="Input speech",
|
61 |
+
type="filepath",
|
62 |
+
source="microphone",
|
63 |
+
visible=False,
|
64 |
+
)
|
65 |
+
input_audio_file = gr.Audio(
|
66 |
+
label="Input speech",
|
67 |
+
type="filepath",
|
68 |
+
source="upload",
|
69 |
+
visible=True,
|
70 |
+
)
|
71 |
+
|
72 |
+
btn = gr.Button("Translate")
|
73 |
+
|
74 |
+
with gr.Column():
|
75 |
+
output_audio = gr.Audio(
|
76 |
+
label="Translated speech",
|
77 |
+
autoplay=False,
|
78 |
+
streaming=False,
|
79 |
+
type="numpy",
|
80 |
+
)
|
81 |
+
output_text = gr.Textbox(label="Translated text")
|
82 |
+
|
83 |
+
audio_source.change(
|
84 |
+
fn=update_audio_ui,
|
85 |
+
inputs=audio_source,
|
86 |
+
outputs=[
|
87 |
+
input_audio_mic,
|
88 |
+
input_audio_file,
|
89 |
+
],
|
90 |
+
queue=False,
|
91 |
+
api_name=False,
|
92 |
+
)
|
93 |
+
|
94 |
+
btn.click(
|
95 |
+
fn=s2st,
|
96 |
+
inputs=[
|
97 |
+
audio_source,
|
98 |
+
input_audio_mic,
|
99 |
+
input_audio_file,
|
100 |
+
],
|
101 |
+
outputs=[output_audio, output_text],
|
102 |
+
api_name="run",
|
103 |
+
)
|
104 |
+
|
105 |
+
demo.queue(max_size=50).launch()
|
106 |
+
|
107 |
+
|
108 |
+
if __name__ == '__main__':
|
109 |
+
main()
|
output.wav
ADDED
Binary file (136 kB). View file
|
|