baoshiwei
2025-04-15 776a127b8db01cd4338f4db2a84ea567a65bff9f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from deepspeech import Model
import scipy.io.wavfile as wav
import numpy as np
 
# 指定模型和评分器文件路径
model_path = 'model/deepspeech-0.9.3-models-zh-CN.pbmm'
scorer_path = 'model/deepspeech-0.9.3-models-zh-CN.scorer'
 
# 初始化DeepSpeech模型
ds = Model(model_path)
ds.enableExternalScorer(scorer_path)
 
# 加载音频文件
audio_path = 'audio/input.wav'
fs, audio = wav.read(audio_path)
 
# 进行语音转文字
text = ds.stt(audio)
 
print('Transcribed text:', text)