当前位置: 首页 > news >正文

TensorFlow2 study notes[1]

文章目录

  • audio
  • references

audio

  1. it is simple to install tensorflow as follows:
pip install torch torchvision torchaudio
  1. tf.audio.decode_wav
    you can condense a 16-bit PCM WAV file into a float tensor.
import tensorflow as tf# Read the WAV file as a byte string
contents = tf.io.read_file("audio_file.wav")# Decode the WAV file
audio, sample_rate = tf.audio.decode_wav(contents, desired_channels=1)print("Audio shape:", audio.shape)  # [samples, channels]
print("Sample rate:", sample_rate.numpy())  # e.g., 44100 (Hz)
  1. tf.audio.encode_wav achive the data Encoding of audio with the WAV file format.
import tensorflow as tf
import matplotlib.pyplot as plt# Generate a simple sine wave (1 second, 440 Hz, mono)
sample_rate = 44100  # 采样率 (44.1 kHz)
frequency = 440.0    # 频率 (440 Hz, A4 音)
duration = 2.0       # 时长 (2 秒)# 生成时间轴 (0 到 1 秒)
t = tf.linspace(0.0, duration, int(sample_rate * duration))# 生成 440 Hz 正弦波
audio = tf.sin(2 * 3.141592 * frequency * t)# 绘制前 5 毫秒的波形(约 2 个周期)
plt.plot(t[:200], audio[:200])  # 44100 Hz / 440 Hz ≈ 100 点/周期
plt.title("440 Hz 正弦波 (采样率 44.1 kHz)")
plt.xlabel("时间 (秒)")
plt.ylabel("振幅")
plt.show()
# Encode to WAV format
audio = tf.expand_dims(audio, axis=-1) 
wav_data = tf.audio.encode_wav(audio, sample_rate)# Save to a file
tf.io.write_file("test.wav", wav_data)

在这里插入图片描述

references

  1. https://tensorflow.google.cn/api_docs/python/tf/all_symbols
  2. deepseek
http://www.dtcms.com/a/275041.html

相关文章:

  • 9.卷积神经网络操作
  • 【网络编程】KCP——可靠的 UDP 传输协议——的知识汇总
  • 公链的主要特征有哪些?
  • 【Docker#1】技术架构演进之路
  • Script Error产生的原因及解法
  • 新品上架后,亚马逊卖家如何高效投放广告
  • 自信的本质:在克服逆境的过程中爱上自己
  • 四、神经网络——正则化方法
  • Operation Blackout 2025 Phantom Check hayabusa+ControlSet001+VirtualBox
  • 【笔记】训练步骤代码解析
  • docker安装Consul笔记
  • Java(7.11 设计模式学习)
  • PLC框架-1.3- 汇川PN伺服(3号报文)
  • 多种人脸处理方案——人脸裁剪
  • Webview 中可用的 VS Code 方法
  • G1 垃圾回收算法详解
  • 【TCP/IP】16. 简单网络管理协议
  • 天晟科技携手万表平台,共同推动RWA项目发展
  • 从「小公司人事」到「HRBP」:选对工具,比转岗更能解决成长焦虑
  • Java大厂面试故事:谢飞机的互联网音视频场景技术面试全纪录(Spring Boot、MyBatis、Kafka、Redis、AI等)
  • kubernetes单机部署踩坑笔记
  • DIDCTF-蓝帽杯
  • 谷歌云代理商:谷歌云TPU/GPU如何加速您的AI模型训练和推理
  • 【数据结构与算法】206.反转链表(LeetCode)
  • C++:非类型模板参数,模板特化以及模板的分离编译
  • 实现将文本数据(input_text)转换为input_embeddings的操作
  • 《从依赖纠缠到接口协作:ASP.NET Core注入式开发指南》
  • Vue 表单开发优化实践:如何优雅地合并 `data()` 与 `resetForm()` 中的重复对象
  • Sigma-Aldrich 细胞培养实验方案 | 通过Hoechst DNA染色检测细胞的支原体污染
  • 拔高原理篇