数学建模社区-数学中国

标题: 从音频文件中识别语音 [打印本页]

作者: 2744557306    时间: 2024-4-26 11:07
标题: 从音频文件中识别语音
  1. import speech_recognition as sr
    ; V7 p5 @3 i! w% v- s/ L

  2. 3 t1 T9 p: q9 P) u0 X# e
  3. recognizer = sr.Recognizer()
      S% s$ X+ c, b. l1 b9 L
  4. audio_file = "audio-file.wav"
    - x7 H, e& p! P% k6 Q2 ?

  5. 2 f/ ?7 _& A2 l+ }% }( `
  6. with sr.AudioFile(audio_file) as source:
    % f9 B" J3 G: F( U) u
  7.     audio = recognizer.record(source)
    ) h; l' n: ~. i3 ~% E
  8. # B& x) V; {% ^
  9.     try:
    $ v, V9 F3 T4 ^1 w3 a; {5 B9 c
  10.         print("音频中说的是:" + recognizer.recognize_google(audio))' Q( `' y" V* F: e) b. i
  11.     except sr.UnknownValueError:
    " f8 G' x- I5 z: x( J, z
  12.         print("无法识别音频")
    9 [, |: @+ x* `( q
复制代码

* y5 @- s' {) u+ y




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5