Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
VisualDL
提交
a45c354e
V
VisualDL
项目概览
PaddlePaddle
/
VisualDL
1 年多 前同步成功
通知
88
Star
4655
Fork
642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
2
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VisualDL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a45c354e
编写于
8月 17, 2020
作者:
走神的阿圆
提交者:
GitHub
8月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modify add_audio (#751)
上级
7db24c50
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
27 deletion
+16
-27
demo/components/audio_test.py
demo/components/audio_test.py
+4
-26
demo/components/test.wav
demo/components/test.wav
+0
-0
visualdl/component/base_component.py
visualdl/component/base_component.py
+12
-1
未找到文件。
demo/components/audio_test.py
浏览文件 @
a45c354e
...
...
@@ -14,35 +14,13 @@
# =======================================================================
# coding=utf-8
from
visualdl
import
LogWriter
import
numpy
as
np
import
wave
def
read_audio_data
(
audio_path
):
"""
Get audio data.
"""
CHUNK
=
4096
f
=
wave
.
open
(
audio_path
,
"rb"
)
rate
=
f
.
getframerate
()
width
=
f
.
getsampwidth
()
channel
=
f
.
getnchannels
()
wavdata
=
[]
chunk
=
f
.
readframes
(
CHUNK
)
while
chunk
:
data
=
np
.
frombuffer
(
chunk
,
dtype
=
'uint8'
)
wavdata
.
extend
(
data
)
chunk
=
f
.
readframes
(
CHUNK
)
shape
=
[
rate
,
width
,
channel
]
return
shape
,
wavdata
from
scipy.io
import
wavfile
if
__name__
==
'__main__'
:
with
LogWriter
(
logdir
=
"vdl_audio_0713"
)
as
writer
:
audio_shape
,
audio_data
=
read_audio_data
(
"./test.wav"
)
audio_data
=
np
.
array
(
audio_data
)
with
LogWriter
(
logdir
=
"./log/audio_test/train"
)
as
writer
:
sample_rate
,
audio_data
=
wavfile
.
read
(
'./test.wav'
)
writer
.
add_audio
(
tag
=
"audio_tag"
,
audio_array
=
audio_data
,
step
=
0
,
sample_rate
=
audio_shape
[
0
]
)
sample_rate
=
sample_rate
)
demo/components/test.wav
浏览文件 @
a45c354e
无法预览此类型文件
visualdl/component/base_component.py
浏览文件 @
a45c354e
...
...
@@ -131,15 +131,26 @@ def audio(tag, audio_array, sample_rate, step, walltime):
Return:
Package with format of record_pb2.Record
"""
audio_array
=
audio_array
.
squeeze
()
if
abs
(
audio_array
).
max
()
>
1
:
print
(
'warning: audio amplitude out of range, auto clipped.'
)
audio_array
=
audio_array
.
clip
(
-
1
,
1
)
assert
(
audio_array
.
ndim
==
1
),
'input tensor should be 1 dimensional.'
audio_array
=
[
int
(
32767.0
*
x
)
for
x
in
audio_array
]
import
io
import
wave
import
struct
fio
=
io
.
BytesIO
()
wave_writer
=
wave
.
open
(
fio
,
'wb'
)
wave_writer
.
setnchannels
(
1
)
wave_writer
.
setsampwidth
(
2
)
wave_writer
.
setframerate
(
sample_rate
)
wave_writer
.
writeframes
(
audio_array
)
audio_enc
=
b
''
audio_enc
+=
struct
.
pack
(
"<"
+
"h"
*
len
(
audio_array
),
*
audio_array
)
wave_writer
.
writeframes
(
audio_enc
)
wave_writer
.
close
()
audio_string
=
fio
.
getvalue
()
fio
.
close
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录