Skip to content

Commit

Permalink
add kws example
Browse files Browse the repository at this point in the history
  • Loading branch information
jm12138 committed Sep 2, 2023
1 parent fe8dd26 commit fbdf614
Showing 1 changed file with 58 additions and 9 deletions.
67 changes: 58 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,66 @@ A third-party Python SDK for a iFLYTEK MSC. Using for ASR, TSS, KWS.
import msc
```

* Login MSC SDK
* Voice Wakeup (KWS)

```python
# Set the APP ID
app_id = ''
# Login MSC SDK
msc.MSPLogin(
usr=None,
pwd=None,
params="appid={}".format(app_id)
import msc
import pyaudio
from ctypes import string_at, c_void_p
from threading import Event
# Audio Stream
p = pyaudio.PyAudio()
input_stream = p.open(
format=pyaudio.paInt16,
channels=1,
rate=16000,
input=True,
frames_per_buffer=2048
)
# Set APP ID
appid = ''
# Set MSC Client
client = msc.MSC(params=f"appid={appid}")
# Stop Event
stop_event = Event()
# KSW Callback Function
def message_callback(
sessionID: bytes,
msg: int,
param1: int,
param2: int,
info: c_void_p,
userData: c_void_p
):
# Print Result
print('sessionID: ', sessionID.decode('UTF-8'))
print('msg: ', msg)
print('param1: ', param1)
print('param2: ', param2)
print('info: ', string_at(info, param2).decode('UTF-8'))
print('userData: ', userData)
# Stop
stop_event.set()
return 0
# Set IVW Res Path
ivw_res_path = ''
# Start KWS
client.kws(
params=f'ivw_res_path=fo|{ivw_res_path}',
message_callback=message_callback,
stream=input_stream,
chunk_size=2048,
user_data=None,
stop_event=stop_event
)
```

Expand Down

0 comments on commit fbdf614

Please sign in to comment.