首页 > 解决方案 > 在 tf.print 中动态更改 output_stream 的值/文件?

问题描述

我正在使用 Tensorflow 对波形音频文件进行一些处理,并使用tf.printwithoutput_stream选项保存它们。

pcm =contrib_audio.encode_wav(processed_audio,16000)
tf.print(output_stream="file:///tmp/test.wav",summarize=-1)

问题是我无法/tmp/test.wav动态更改值以便存储多个波形文件。

标签: tensorflowaudiostreamwav

解决方案


请参考以下代码。

# Using a counter
for i in range(1,10):
   fname = "test_"+str(i)+".wav" #filename
   path = "//content/sample_data/" #path to save
   fname = "file://{path}{fname}".format(fname=fname, path = path)
   tf.print(output_stream=fname,summarize=-1)

您可以创建动态文本,使其成为唯一的文件名。


推荐阅读