Java 类名:com.alibaba.alink.pipeline.audio.ReadAudioToTensor
Python 类名:ReadAudioToTensor
读取音频文件,并转换为 Alink FloatTensor 格式。
名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 |
---|---|---|---|---|---|---|
outputCol | 输出结果列列名 | 输出结果列列名,必选 | String | ✓ | ||
relativeFilePathCol | 文件路径列 | 文件路径列 | String | ✓ | ||
rootFilePath | 文件路径 | 文件路径 | String | ✓ | ||
sampleRate | 采样率 | 采样率 | Integer | ✓ | ||
channelFirst | Channel维度是否放在Shape的第一位 | 默认为false,参数为false时,放在Shape的最右侧,为true时,放在Shape的最左侧。 | Boolean | false | ||
duration | 采样持续时间 | 采样持续时间 | Double | |||
offset | 采样开始时刻 | 采样开始时刻 | Double | 0.0 | ||
reservedCols | 算法保留列名 | 算法保留列 | String[] | null | ||
numThreads | 组件多线程线程个数 | 组件多线程线程个数 | Integer | 1 |
** 以下代码仅用于示意,可能需要修改部分代码或者配置环境后才能正常运行!**
dataDir = "https://alink-test-data.oss-cn-hangzhou.aliyuncs.com/audio"; df = pd.DataFrame([ ["246.wav"], ["247.wav"] ]) allFiles = BatchOperator.fromDataframe(df, schemaStr='wav_file_path string') SAMPLE_RATE = 16000 readOp = ReadAudioToTensor().setRootFilePath(dataDir) \ .setSampleRate(SAMPLE_RATE) \ .setRelativeFilePathCol("wav_file_path") \ .setOutputCol("tensor") \ .transform(allFiles) readOp.print()
package example; import com.alibaba.alink.operator.batch.BatchOperator; import com.alibaba.alink.operator.batch.source.MemSourceBatchOp; import com.alibaba.alink.pipeline.audio.ReadAudioToTensor; import org.junit.Test; public class ReadAudioToTensorTest { @Test public void testReadAudioToTensor() throws Exception { String dataDir = "https://alink-test-data.oss-cn-hangzhou.aliyuncs.com/audio"; String[] allFiles = {"246.wav", "247.wav"}; int sampleRate = 16000; BatchOperator source = new MemSourceBatchOp(allFiles, "wav_file_path"); ReadAudioToTensor pipe = new ReadAudioToTensor() .setRootFilePath(dataDir) .setSampleRate(sampleRate) .setRelativeFilePathCol("wav_file_path") .setDuration(2) .setOutputCol("tensor"); pipe.transform(source).print(); } }
wav_file_path | tensor |
---|---|
246.wav | FLOAT#32000,1#-7.324219E-4 -0.0010986328 -9.460449E-4 … |
247.wav | FLOAT#32000,1#-0.0057678223 -0.0051574707 -0.0036315918 … |