how to convert wav to text file on windows with python - speech-to-text

i used this command to install the library "pocketsphinx". I have python 3.5
pip install pocketsphinx
How can i convert wav file to text file on windows (command prompt)
Can I get "what time to what time : what text/statement" from this library? If not, how can i get it?
(For example : 00 to 09 : I am going to the market , 10-14 : But why are you coming with me, .. )

Related

modulenotfounderror no module named 'visual'?

I am trying to convert a py file from VPython 2.7 Program to exe file (in windows) but I am getting an error that says.
ModulNotFoundError: No module named 'visual'
Can you guys please guide me on how can I resolve this issue?
I want my Python visual file to be able to receive input and give 3D output when it' converted to EXE mode.
For example; I want to create an exe file from this codes that are in py to create my 3D output as an exe file.
from visual import*
from time import*
from math import*
L1=0.1
H1=2.8
W1=4.0
W1=0.1
W2=0.0
T1=.15
L1 = 6
a1=-H1/2
b1=H1/2
c1=L1/2
d1=-L1/2
e1=W1/2
floor=box(pos=vector(0,a1,0),color=color.white,length=L1,height=T1,width=W1+T1)
right=box(pos=vector(c1,0,0),color=color.orange,length=T1,height=H1,width=W1)
left=box(pos=vector(d1,0,0),color=color.white,length=T1,height=H1,width=W1)
behind=box(pos=vector(0,0,e1),color=color.white,length=L1+T1,height=H1,width=T1)
front=box(pos=vector(0,0,f1),color=color.white,length=L1+T1,height=H1,width=T1)

Running nltk module with python

I have installed python 38 on my PC (Windows 10 Pro, 64 bit). It is in the following directory;
C:\Users\rschafish\AppData\Local\Programs\Python\Python38-32
I then downloaded nltk-3.5 (the download is a zip file obtained irectly from the nltk website) and I unzipped it and placed the files in the python Lib directory.
C:\Users\rschafish\AppData\Local\Programs\Python\Python38-32\Lib\nltk-3.5
I opened python using IDLE (Python 3.8.3 Shell) and the opening line from python includes;
(Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020 22:20:19 MSC vl1925 32 bit Intel on win32)
I then entered >>> import nltk and received the following error message;
Traceback (most recent call last): File”<pyshell#0>”, line 1 in import nltk
ModuleNotFoundError: no module named ’nltk’
It appears that this may be a problem related to the python path however I thought that placing the nltk files in the python Lib directory is what should be done. I have searched the issue online but did not find any solutions that have worked for me.
Help and advice will be greatly appreciated.

string: syntax error on raspbian jelly, flawless on IDLE windows 8

My script (python 3.6) raises an error when executed on my RPI (Linux raspberrypi 4.9.59-v7+ #1047), but runs flawlessly when executed with IDLE, on a windows 8.1 PC.
Basically, I want to create a gzip archive from "data.json" file.
Here is a light version:
import time
import gzip
inputFile = "/path/to/data.json"
dataArchiveName = f"{inputFile}-{time.localtime().tm_mday}_{time.localtime().tm_mon}_{time.localtime().tm_year}.gz"
...
When I run the script, the following exception is raised:
File "dataManager2.py", line 96
dataArchiveName = f"{inputFile}-{time.localtime().tm_mday}_{time.localtime().tm_mon}_{time.localtime().tm_year}.gz"
^
SyntaxError: invalid syntax
I do not understand why... Any idea ?
Thank you in advance
f-strings were introduced in Python 3.6, since you are using Python 3.5 on you Raspberry Pi, you will have to either install Python 3.6 on it or use older way of formatting strings, this should work:
dataArchiveName = "%s-%s_%s_%s.gz" % (inputFile, time.localtime().tm_mday, time.localtime().tm_mon, time.localtime().tm_year)

Python Pillow and Font Conversion

I have just installed python pillow 5 on a raspberry pi. It installed fine, and works ok.
The issue i am having is finding a pilfont.py file.
I have several bdf fonts i need to convert and have been searching the web for how to do this.
All the information i have found points to the pilfont utility, but i cant find it on the pi.
Can anyone point me in the right direction as to where it is, I understand how to use it to convert the fonts, just can not activate it.
cheers
As of at least October 2018, the previous answer doesn't work anymore since the package does not include the pilfont utility. But it turns out you don't need to spend time hunting down an external utility, since pilfont is just a very simple script you recreate in just a couple of minutes.
Here's my own "pilfont utility" which converts all the .bdf and .pcf fonts in the current directory to .pil and .pbm:
#!/usr/bin/env python
# Author: Peter Samuel Anttila
# License: The Unlicense <http://unlicense.org, October 16 2018>
from PIL import BdfFontFile
from PIL import PcfFontFile
import os
import glob
font_file_paths = []
current_dir_path = os.path.dirname(os.path.abspath(__file__))
font_file_paths.extend(glob.glob(current_dir_path+"/*.bdf"))
font_file_paths.extend(glob.glob(current_dir_path+"/*.pcf"))
for font_file_path in font_file_paths:
try:
with open(font_file_path,'rb') as fp:
# despite what the syntax suggests, .save(font_file_path) won't
# overwrite your .bdf files, it just creates new .pil and .pdm
# files in the same folder
if font_file_path.lower().endswith('.bdf'):
p = BdfFontFile.BdfFontFile(fp)
p.save(font_file_path)
elif font_file_path.lower().endswith('.pcf'):
p = PcfFontFile.PcfFontFile(fp)
p.save(font_file_path)
else:
# sanity catch-all
print("Unrecognized extension.")
except (SyntaxError,IOError) as err:
print("File at '"+str(font_file_path)+"' could not be processed.")
print("Error: " +str(err))
For those on a tight deadline:
You don't need the utility. Just use the following code to convert it yourself:
with open(font_file_path,'rb') as fp:
p = BdfFontFile.BdfFontFile(fp) #PcfFontFile if you're reading PCF files
# won't overwrite, creates new .pil and .pdm files in same dir
p.save(font_file_path)
It throws SyntaxError and/or IOError in case the file can't be read as a BDF or PCF file.
Seems you installed pillow 5 via pip3. I did this myself, too and it did not include the pilfont utility. Even did not find the file in the pillow git. Did not find a deprecated info either. Therefore I suggest this workaround:
create an empty dir and change into it.
Now:
apt-get download python3-pil
to download the raspbian package which includes pillow 4 including pilfont. This does not install the package.
Next extract your downloaded deb package. Filename may vary:
ar -x python3-pil_4.0.0-4.deb
After that you have some files one is data.tar.xz which you need to extract:
tar -xvf data.tar.xz
This gives you ./usr/bin/pilfont
Now you may copy it to /usr/bin/
sudo cp ./usr/bin/pilfont /usr/bin/pilfont
After that you can delete the downloaded archive and its extracted contents.

UnicodeDecodeError When Opening a tar File in Python 3

I'm using Linux Mint 18.1 and Python 3.5.2.
I have a library that currently works using Python 2.7. I need to use the library for a Python 3 project. I'm updating it and have run into a unicode problem that I can't seem to fix.
First, a file is created via tar cvjf tarfile.tbz2 (on a Linux system) and is later opened in the Python library as open(tarfile).
If I run the code as is, using Python 3, I get the following error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc1 in position 11: invalid start byte
My first attempt at a fix was to open it as open(tarfile, encoding='utf-8') as I was under the impression that tar would just use what the file system gave it. When I do this, I get the same error (the byte value changes).
If I try with another encoding, say latin-1, I get the following error:
TypeError: Unicode-objects must be encoded before hashing
Which leads me to believe that utf-8 is correct, but I might be misunderstanding.
Can anyone provide suggestions?
I was going down the wrong path thinking this was some strange encoding problem. When it was just a simple problem with that fact that open() defaults to read as text (r). In Python 2 it's a no-op.
The fix is to open(tarfile, 'rb').
The head fake with unicode...should have seen this one coming. :facepalm:

Resources