1、pydub
from pydub import AudioSegment
from pydub.playback import play
song = AudioSegment.from_wav(r"C:\Users\loong\Downloads\zh.wav")
play(song)
2、playsound
from playsound import playsound
playsound(r"voice.wav")
3、streamlit
import streamlit as st
##输入字节流
st.audio(audio_bytes) ##展示前端语音控件
离线音频自动播放
import base64
import streamlit as st
## 文件
file_path = "audio123.wav"
with open(file_path, "rb") as f:
audio_bytes = f.read()
audio_base64 = base64.b64encode(audio_bytes).decode('utf-8')
audio_tag = f'<audio autoplay="true" src="data:audio/wav;base64,{audio_base64}">'
st.markdown(audio_tag, unsafe_allow_html=True)
##录制声音
4、gradio
版本:gradio-4.16.0 在3.38不生效
gr.Audio既可以输入也可以播放这个函数接口
inputs=gr.Audio(type=“file”, label=“上传音频文件”), # 输入组件,允许用户上传音频文件
outputs=gr.Audio(label=“播放音频”, autoplay=True)
import gradio as gr
def greet(name):
return "Hello " + name + "!"
# 创建 Gradio 界面
with gr.Blocks() as demo:
with gr.Row():
inp_ref = gr.Audio(label="请上传3~10秒内参考音频,超过会报错!", sources=["microphone", "upload"], type="filepath")
gr.Markdown("### Greet")
# gr.Input(type="text", label="Name:")
with gr.Row():
gr.Button("Greet")
gr.Markdown("### Response")
# gr.Markdown("### ", output=True)
# 启动应用
demo.launch()
5、gradio 页面图像、视频及调用摄像头
gr.Image(
type=‘numpy’,
label=‘Input Image’
)
gr.Video(
label=‘Input Video’
)
with gr.Row():
input_image_component = gr.Image(
type='numpy',
label='Input Image'
)
output_image_component = gr.Image(
type='numpy',
label='Output Image'
)
with gr.Row():
input_video_component = gr.Video(
label='Input Video'
)
output_video_component = gr.Video(
label='Output Video'
)