-1

I'm trying to implement deepspeech and as part of the implementation, I'm trying to run the below code. I have installed python3 and deepspeech-0.9.3

While running the below code, I'm getting an error as line 17, in <module> model = deepspeech.Model(MODEL_FILE_PATH, BEAM_WIDTH) TypeError: __init__() takes 2 positional arguments but 3 were given

import deepspeech
import numpy as np
import os
import pyaudio
import time

# DeepSpeech parameters
DEEPSPEECH_MODEL_DIR = 'deepspeech-0.9.3-models'
MODEL_FILE_PATH = os.path.join(DEEPSPEECH_MODEL_DIR, 'output_graph.pbmm')
BEAM_WIDTH = 500
LM_FILE_PATH = os.path.join(DEEPSPEECH_MODEL_DIR, 'lm.binary')
TRIE_FILE_PATH = os.path.join(DEEPSPEECH_MODEL_DIR, 'trie')
LM_ALPHA = 0.75
LM_BETA = 1.85

# Make DeepSpeech Model
model = deepspeech.Model(MODEL_FILE_PATH, BEAM_WIDTH)
model.enableDecoderWithLM(LM_FILE_PATH, TRIE_FILE_PATH, LM_ALPHA, LM_BETA)

# Create a Streaming session
context = model.createStream()

# Encapsulate DeepSpeech audio feeding into a callback for PyAudio
text_so_far = ''
def process_audio(in_data, frame_count, time_info, status):
    global text_so_far
    data16 = np.frombuffer(in_data, dtype=np.int16)
    model.feedAudioContent(context, data16)
    text = model.intermediateDecode(context)
    if text != text_so_far:
        print('Interim text = {}'.format(text))
        text_so_far = text
    return (in_data, pyaudio.paContinue)

# PyAudio parameters
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 16000
CHUNK_SIZE = 1024

# Feed audio to deepspeech in a callback to PyAudio
audio = pyaudio.PyAudio()
stream = audio.open(
    format=FORMAT,
    channels=CHANNELS,
    rate=RATE,
    input=True,
    frames_per_buffer=CHUNK_SIZE,
    stream_callback=process_audio
)

print('Please start speaking, when done press Ctrl-C ...')
stream.start_stream()

try: 
    while stream.is_active():
        time.sleep(0.1)
except KeyboardInterrupt:
    # PyAudio
    stream.stop_stream()
    stream.close()
    audio.terminate()
    print('Finished recording.')
    # DeepSpeech
    text = model.finishStream(context)
    print('Final text = {}'.format(text))
Deepak Bandi
  • 1,854
  • 4
  • 21
  • 37

2 Answers2

0

you have either given more arguments or you are not using self keyword in the init

Diwakar SHARMA
  • 573
  • 7
  • 24
-1

You are using deprecated code.

You are trying to use 0.9 model with 0.6 code. Since 0.7 you don't longer use lm.binary and trie for the language model. And there is lot more wrong with your code.

Check the 0.9 docs.

And maybe use one of the current examples. Depending on what your use case is.

Olaf
  • 158
  • 7
  • While likely true, this does not answer the question at all – Mad Physicist Jan 24 '21 at 10:37
  • Yep, but he either uses an older model which he doesn't have or switches to newer code. But other params like the lms won't work. Therefore a simple "do this" won't work. He's got to check the manual. – Olaf Jan 24 '21 at 13:56