Reputation: 1
I am trying to use PocketSphinx to extract Phonemes from WAV audio files in google colab. I am initizialising PockerSphinx through a directory in my google drive.
This is the code:
sys.path.append('/content/drive/MyDrive/pocketsphinx-
master/lib/python3.10/site-packages')
import os
from pocketsphinx import Pocketsphinx, Decoder, Config
import sys
import soundfile as sf
from pydub import AudioSegment
# Define directories for models and data
MODELDIR = "/content/drive/MyDrive/pocketsphinx-master/model"
ACOUSTIC_MODEL_DIR = os.path.join(MODELDIR, 'en-us')
PHONETIC_MODEL_FILE = os.path.join(MODELDIR, 'en-us-phone.lm.bin')
DATADIR = "/content/drive/MyDrive/WAV"
# Create a decoder with the correct configuration
config = Config()
config.set_string('-hmm', ACOUSTIC_MODEL_DIR)
config.set_string('-allphone', PHONETIC_MODEL_FILE)
config.set_float('-lw', 2.0)
config.set_float('-beam', 1e-60)
config.set_float('-pbeam', 1e-50)
config.set_string('-logfn', '/content/drive/MyDrive/pocketsphinx-master/pocketsphinx.log')
# Initialize the decoder using the configuration
try:
decoder = Decoder(config)
print("Decoder initialized successfully.")
except RuntimeError as e:
print(f"Failed to initialize decoder: {e}")
# Check if the decoder is initialized and then process the sample audio file
if 'decoder' in locals():
decoder.start_utt()
with open(os.path.join(DATADIR, 'Depression_English.wav'), 'rb') as stream:
while True:
buf = stream.read(1024)
if buf:
decoder.process_raw(buf, False, False)
else:
break
decoder.end_utt()
# Print the hypothesis (recognized phonemes)
hypothesis = decoder.hyp()
if hypothesis is not None:
print('Best hypothesis:', hypothesis.hypstr)
print('Phonemes:', [seg.word for seg in decoder.seg()])
else:
print('No hypothesis formed.')
else:
print("Decoder could not be initialized.")
This is the directory for the pocketsphinx master
This is whats in the model folder
This is whats in the en-us folder
I tried modifying the file paths and Im not sure the file paths are the issue. I think it might be an installation error or a version mismatch but I cant find what the error is in the PocketSphinx Directory. I also tried installing pocketsphinx in my terminal.
Upvotes: 0
Views: 27