Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 12e2d91

Browse files
committed
Updated for new changes
1 parent ead72f0 commit 12e2d91

File tree

3 files changed

+65
-19
lines changed

3 files changed

+65
-19
lines changed

example.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from os import environ, path
2+
3+
from pocketsphinx.pocketsphinx import *
4+
from sphinxbase.sphinxbase import *
5+
6+
MODELDIR = "pocketsphinx/model"
7+
DATADIR = "pocketsphinx/test/data"
8+
9+
# Create a decoder with certain model
10+
config = Decoder.default_config()
11+
config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us'))
12+
config.set_string('-lm', path.join(MODELDIR, 'en-us/en-us.lm.dmp'))
13+
config.set_string('-dict', path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))
14+
decoder = Decoder(config)
15+
16+
# Decode streaming data.
17+
decoder = Decoder(config)
18+
decoder.start_utt()
19+
stream = open(path.join(DATADIR, 'goforward.raw'), 'rb')
20+
while True:
21+
buf = stream.read(1024)
22+
if buf:
23+
decoder.process_raw(buf, False, False)
24+
else:
25+
break
26+
decoder.end_utt()
27+
print ('Best hypothesis segments: ', [seg.word for seg in decoder.seg()])

readme.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
pocketsphinx-python
22
===================
33

4-
Python interface to CMU SphinxBase and PocketSphinx libraries
4+
Python interface to CMU SphinxBase and PocketSphinx libraries created with SWIG.
5+
Pocketsphinx packages include python support, however, it is based on Automake and
6+
not well supported on Windows.
7+
8+
This package provides module created with Python distutils setup and can be more
9+
portable.
510

611
Supported Platforms
712
-------------------
@@ -63,16 +68,35 @@ cd pocketsphinx-python
6368
sudo python setup.py install
6469
```
6570

66-
Import
67-
------
71+
Basic usage
72+
-----------
6873

6974
```python
70-
try:
71-
# Python 2.x
72-
from sphinxbase import Config
73-
from pocketsphinx import Decoder
74-
except ImportError:
75-
# Python 3.x
76-
from sphinxbase.sphinxbase import Config
77-
from pocketsphinx.pocketsphinx import Decoder
75+
from os import environ, path
76+
77+
from pocketsphinx.pocketsphinx import *
78+
from sphinxbase.sphinxbase import *
79+
80+
MODELDIR = "pocketsphinx/model"
81+
DATADIR = "pocketsphinx/test/data"
82+
83+
# Create a decoder with certain model
84+
config = Decoder.default_config()
85+
config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us'))
86+
config.set_string('-lm', path.join(MODELDIR, 'en-us/en-us.lm.dmp'))
87+
config.set_string('-dict', path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))
88+
decoder = Decoder(config)
89+
90+
# Decode streaming data.
91+
decoder = Decoder(config)
92+
decoder.start_utt()
93+
stream = open(path.join(DATADIR, 'goforward.raw'), 'rb')
94+
while True:
95+
buf = stream.read(1024)
96+
if buf:
97+
decoder.process_raw(buf, False, False)
98+
else:
99+
break
100+
decoder.end_utt()
101+
print ('Best hypothesis segments: ', [seg.word for seg in decoder.seg()])
78102
```

setup.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,10 @@
3636
3737
.. code:: python
3838
39-
try:
40-
# Python 2.x
41-
from sphinxbase import Config
42-
from pocketsphinx import Decoder
43-
except ImportError:
44-
# Python 3.x
45-
from sphinxbase.sphinxbase import Config
46-
from pocketsphinx.pocketsphinx import Decoder
39+
from sphinxbase.sphinxbase import Config
40+
from pocketsphinx.pocketsphinx import Decoder
4741
"""
42+
4843
import sys
4944
from glob import glob
5045
try:

0 commit comments

Comments
 (0)