File: simple.py

package info (click to toggle)
pocketsphinx 5.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,236 kB
  • sloc: ansic: 54,519; python: 2,438; sh: 566; cpp: 410; perl: 342; yacc: 93; lex: 50; makefile: 30
file content (23 lines) | stat: -rw-r--r-- 695 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python3
"""
Recognize a single utterance from a WAV file.

Supporting other file types is left as an exercise to the reader.
"""

# MIT license (c) 2022, see LICENSE for more information.
# Author: David Huggins-Daines <dhdaines@gmail.com>

from pocketsphinx import Decoder
import argparse
import wave

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("audio", help="Audio file to recognize")
args = parser.parse_args()
with wave.open(args.audio, "rb") as audio:
    decoder = Decoder(samprate=audio.getframerate())
    decoder.start_utt()
    decoder.process_raw(audio.getfp().read(), full_utt=True)
    decoder.end_utt()
    print(decoder.hyp().hypstr)