I am getting a error while running a pttsx3 code as root. So the code should save a file and say the words inputted. Here is the code:
import pyttsx3
engine = pyttsx3.init()
s1 = input("Words: ")
engine.say(s1)
engine.save_to_file(s1 ,'try.mp3')
engine.runAndWait()
And here is the error:
ALSA lib pcm_dmix.c:1035:(snd_pcm_dmix_open) unable to open slave
aplay: main:831: audio open error: Device or resource busy
Running this code without root works, but I need to run it as root because I am adding it to another code that needs root. Note: I tried using gtts but I need a male voice to beatbox.
Related
I am trying to transcribe text from an audio file with the speech recognition module in python. However, whenever I try to run the code, the module throws an OSError. I have disabled the lines of code that say “try” and “except”, since the code returns “Sorry... run again...” if I don’t. I have made sure that the audio sample is 16 bit, but even then I can’t get it to work. I am running Pythonista on an iPad Air, but I get the same results when using a MacBook Air. Is there a problem with software compatibility? I am also new to python, so can anybody help me with this issue?
The code:
#import library
import os
import speech_recognition as sr
import wave
# Initialize recognizer class (for recognizing the speech)
r = sr.Recognizer()
# Reading Audio file as source
# listening the audio file and store in audio_text variable
with sr.AudioFile('audio1.wav') as source:
audio_text = r.listen(source)
# recoginize_() method will throw a request error if the API is unreachable, hence using exception handling
#try:
# using google speech recognition
text = r.recognize_google(audio_text)
print('Converting audio transcripts into text ...')
print(text)
#except:
#print('Sorry.. run again...')
The Traceback:
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/34AFF89C-1113-4021-BF04-27338D54F87B/Pythonista3/Documents/program/program.py", line 21, in <module>
text = r.recognize_google(audio_text)
File "/private/var/mobile/Containers/Shared/AppGroup/34AFF89C-1113-4021-BF04-27338D54F87B/Pythonista3/Documents/site-packages-3/speech_recognition/__init__.py", line 828, in recognize_google
convert_width=2 # audio samples must be 16-bit
File "/private/var/mobile/Containers/Shared/AppGroup/34AFF89C-1113-4021-BF04-27338D54F87B/Pythonista3/Documents/site-packages-3/speech_recognition/__init__.py", line 445, in get_flac_data
flac_converter = get_flac_converter()
File "/private/var/mobile/Containers/Shared/AppGroup/34AFF89C-1113-4021-BF04-27338D54F87B/Pythonista3/Documents/site-packages-3/speech_recognition/__init__.py", line 1196, in get_flac_converter
raise OSError("FLAC conversion utility not available - consider installing the FLAC command line application by running `apt-get install flac` or your operating system's equivalent")
OSError: FLAC conversion utility not available - consider installing the FLAC command line application by running `apt-get install flac` or your operating system's equivalent
I am running the following SAP GUI script using python. I am SAP session open, but I am not getting application information using GetScriptingEngine.
My code
import sys, win32com.client
sapguiauto = win32com.client.GetObject("SAPGUI")
print(sapguiauto)
sapapplication = sapguiauto.GetScriptingEngine
print(sapapplication)
Error
C:\Users\a4fhbzz\AppData\Local\Programs\Python\Python39\python.exe C:/Users/a4fhbzz/PycharmProjects/untitled/ILM/SAPGUI/TestLogonSAPGUI.py
COMObject SAPGUI>
COMObject unknown
Process finished with exit code 0
I am trying to access a test text file on a server with the command os.startfile but I can't seem to make it work. I know it only fails because the text file is on the server and not on the computer but I have no idea how to access it.
Here's my code :
from os import startfile
path = "//10.2.30.61/c$/Qlikview_Tropal/Raport/test1.txt"
startfile("//10.00.00.00/c$/test/test1/test1.txt")
And I get this error : FileNotFoundError: [WinError 2]. I am on windows by the way.
Update_1 : I tried the enter os.startfile(os.path.normpath()) and i get this error : "filenotfounderror winerror 53 the network path was not found"
Thank you !!
You can do
from os import start file
#put two \\ to get one \
path = "\\\\10.2.30.61\\c$\\Qlikview_Tropal\\Raport\\test1.txt"
startfile(r"\\10.00.00.00\c$\test\test1\test1.txt")
https://stackoverflow.com/a/43205543/14579156
Having problems finding how to add songs to playlist on Raspberry PI (Jessie Lite)
When I am trying to add file, either giving directory name or file it says :
mpd.base.CommandError: [50#0] {add} Not found
or "bad URI"
I changed the music directory in mpd.conf to home directory but it didn't help. Can i change MPD music directory from Python?
from mpd import MPDClient
client = MPDClient()
client.connect("localhost", 6600)
client.update()
//client.add("music/")
client.add("file.mp3")
Aim is just to manage playlist, create and remove songs on demand with python
Answer was found here https://stackoverflow.com/a/37632225/2838794
sudo nano /etc/mpd.conf
Inside file:
bind_to_address "/run/mpd/socket"
After saving the file
export MPD_HOST=/run/mpd/socket
systemctl restart mpd
Objective:
I am using Ubuntu 16.04 and am using WMI-CLient-Wrapper module to connect to a remote Windows Machine and send an executable to it(eg. Process Explorer) and further execute it and collect the logs it creates and fetch them back to my Linux Machine for further processing. Using WMI CLient Wrapper is the only option available as WMI Module doesn't work with Linux.
Problem:
I am able to send the file to the remote Windows machine, by establishing a connection using WMI-Client-Wrapper and SMB File Transfer Mechanism. After that when I try to create a Process for the same and try to execute that process it gives me an error stating that some of the attributes that WMI actually has, are not supported by WMI client Wrapper.
What I tried
Python Code:
import os
import wmi_client_wrapper as wmic
from socket import *
import time
wmic = wmic.WmiClientWrapper(
host ="192.168.115.128",
username = "LegalWrongDoer",
password = "sasuke14"
)
SW_SHOWNORMAL = 1
str = "smbclient //192.168.115.128/C$ -U LegalWrongDoer%sasuke14 -c \'put \"procexp64.exe\"\'"
os.system(str)
print("Folder sent")
process_startup = wmic.Win32_ProcessStartup.new()
process_startup.ShowWindow = SW_SHOWNORMAL
process_id, result = wmic.Win32_Process.Create(CommandLine="C:/procexp64.exe", ProcessStartupInformation=process_startup)
process_startup.ShowWindow = SW_SHOWNORMAL
if result == 0:
print("Process started successfully")
else:
print("Sorry, but can't execute Process!")
When I run this python file, it gives me the output to the initial query I make. But the Process_StartUp fails.
Further Traceback Calls:
Traceback (most recent call last):
File "WMIClient.py", line 22, in <module>
process_startup = wmic.Win32_ProcessStartup.new()
AttributeError: 'WmiClientWrapper' object has no attribute 'Win32_ProcessStartup'
I'd be extremely grateful if anyone of you can be able to help me through this. Thanks in advance :)
Well I finally managed to get a work-around for this whole scenario, and it might look a little messy but it sure does work for me.
Firstly I use smbclient to transfer the executable to the end-point where I want to execute it. Inside my code I use os.system() calls to make this happen.
import os
str1 = "smbclient //'<HostMachineIP>'/admin$ -U '<domain>\\<username>%<password>' -c \'lcd /usr/local/acpl/bin/endPoint/; put \"EndPointForeignsics.exe\"\'"
os.system(str1)
This helps me put the executable in desired shared folder that the user has access(Admin in my case) to and then use WMI-query through a tool called Winexe to get access to the console/command prompt of the end-point. I use another os.system() call to execute this again.
str2 = r'/usr/local/bin/winexe -U "<domain>\\<username>%<password>" //<HostMachineIP> "cmd /c c:\windows\EndPointForeignsics.exe '
os.system(str2)
P.S:-- Winexe is a tool that you'll have to download off the internet and compile it. It may take some time and effort to do that, but is quite achievable. You'll get a lot of help on the same from StackOverflow and Documentation of the tool.