Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import pyaudio
from deepspeech import Model
import scipy.io.wavfile as wav
import wave
WAVE_OUTPUT_FILENAME = "test_audio.wav"
def record_audio(WAVE_OUTPUT_FILENAME):
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 16000
RECORD_SECONDS = 5
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
frames = [stream.read(CHUNK) for i in range(0, int(RATE / CHUNK * RECORD_SECONDS))]
print("* done recording")
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
def deepspeech_predict(WAVE_OUTPUT_FILENAME):
N_FEATURES = 25
N_CONTEXT = 9
BEAM_WIDTH = 500
LM_ALPHA = 0.75
LM_BETA = 1.85
ds = Model('deepspeech-0.5.1-models/output_graph.pbmm', N_FEATURES, N_CONTEXT, 'deepspeech-0.5.1-models/alphabet.txt', BEAM_WIDTH)
fs, audio = wav.read(WAVE_OUTPUT_FILENAME)
return ds.stt(audio, fs)
if __name__ == '__main__':
record_audio(WAVE_OUTPUT_FILENAME)
predicted_text = deepspeech_predict(WAVE_OUTPUT_FILENAME)
print(predicted_text)
@immohann

This comment has been minimized.

Copy link

@immohann immohann commented Jan 18, 2020

getting : File "C:\Users\mohan.conda\envs\rasa_vof\lib\site-packages\deepspeech_init_.py", line 40, in init
status, impl = deepspeech.impl.CreateModel(*args, **kwargs)
TypeError: CreateModel() takes at most 2 arguments (5 given)

can you help?

@GV2019

This comment has been minimized.

Copy link

@GV2019 GV2019 commented Feb 3, 2020

getting : File "C:\Users\mohan.conda\envs\rasa_vof\lib\site-packages\deepspeech__init__.py", line 40, in init
status, impl = deepspeech.impl.CreateModel(*args, **kwargs)
TypeError: CreateModel() takes at most 2 arguments (5 given)

can you help?

Dear Mohanqwerty5,

Kindly note that you have to use an older version of deepspeech for this model.
pip install deepspeech==0.5.0a5

@immohann

This comment has been minimized.

Copy link

@immohann immohann commented Feb 4, 2020

Ohh thanks, It got solved :)

@Prskriti

This comment has been minimized.

Copy link

@Prskriti Prskriti commented May 11, 2020

getting: AttributeError: 'Model' object has no attribute '_impl' and TypeError: init() takes 2 positional arguments but 6 were given on running deepspeech_test_prediction.py
Could you please help me in resolving the mentioned issues.
Here is the snapshot of the error message:
Screen Shot 2020-05-11 at 2 48 35 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment