Like title, i'm trying to use Qt and FFmpeg to play audio. My code like this:
QAudioOutput *audio_output;
QIODevice *stream_out;
QAudioFormat audio_fmt;
audio_fmt.setSampleRate(44100);
audio_fmt.setChannelCount(2);
audio_fmt.setSampleSize(16);
audio_fmt.setCodec("audio/pcm");
audio_fmt.setByteOrder(QAudioFormat::LittleEndian);
audio_fmt.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info = QAudioDeviceInfo::defaultOutputDevice();
if(!info.isFormatSupported(audio_fmt))
{
audio_fmt = info.nearestFormat(audio_fmt);
}
audio_output = new QAudioOutput(audio_fmt);
When i use QAudioDeviceInfo info = QAudioDeviceInfo::defaultOutputDevice()
i get PulseAudioService: pa_context_connect() failed error.
So how can i fix it?
By the way, i'm using Ubuntu 16.04 and Qt 5.14.2, and i have add 'mutilmedia' to Qt pro file
I checked my Qt file ,and i have audio dir in plugins, it's not lib problem. Also, i read this post ,but i don't know how to fix it, anybody have idea? Thank you guys,and my English is bad, wish you can understand what do i say.
Related
I am trying to build a virtual assistant for exercise, when i attempt to get audio using the microphone live 'Robin' (the V.A) will stay running.
I updated speechrecognitioin, pyaudio, and also reinstalled elasticsearch via homebrew after having to install java 1.8. I also tried adjusting the exception_on_overflow error after shutdown and set it '=False' (at this point i am much beyond my level of knowledge). On top of this to ensure the translation was working correctly i ran the -m speech recognition in terminal (OS: Mac) and it pretty accurately translated the speech. Im stumped.
# take command from microphone
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Absorbing...')
audio = r.listen(source)
try:
print('Recognizing...')
query = r.recognize_google(audio, language='en-US')
print(f'user said:{query}\n')
except KeyboardInterrupt as e:
print('Im sorry, I didnt get that.')
#Begin tasking:
speak('Initializing, Robin...')
wishMe()
takeCommand()
I am hoping for the console to return what i said into text, the goal would then to turn the text into an executable command. Hence the 'takeCommand' function. Yet if Robin cannot detect a sound she will give the output 'Im sorry,'. If theres anything else i can provide let me know. I really appreciate the feedback. Also Im new to stackoverfow I apologize if i didn't format this correctly.
I recently started playing with Processing. I want to create a simple FFT visualizer that will import music file using Sound library. Here's my code and the console output.
Console Output
import processing.sound.*;
SoundFile file;
void setup()
{
size();
background(51);
file = new SoundFile(this, "song.mp3");
file.play();
}
void draw ()
{
}
Can someone explain why is this happening and how it can be fixed?
By the way, sound file (song.mp3) is located in the same folder as the .pde file.
Put the mp3 file in a folder called data which should be located where your .pde file is located.
This might not fix your issue though. If the issue persists, then it's the fault of the SoundFile library and there is nothing you can currently do.
I have heard people recommending the "minim" library. Try to look into that, as continuing to use the SoundFile library will only lead to problems.
I had the same problem when trying to load mono mp3s. Changed them to stereo and they worked.
i am trying to make a media player that generates random subtitles based on nltk library. I am using the vlc python for it, for now i do not care about interface. But i have problem understanding how to put subtitles, even as a srt file.
The function is SubtitleTrack() inside vlc.py. Somewhere else i saw that i must use the add_slave() function.
My code until now is:
import vlc
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new('Test.avi')
Sub = player.add_slave(player,'Test.srt', True)
player.set_media(Media)
player.play()
The version of libvlc is 2.2.6
SubtitleTrack() is a class.
What you want to do is add the subtitles after you hit play. How you do this, from my understanding depends on the version.
import vlc
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new('Test.avi')
player.set_media(Media)
player.play()
player.video_set_subtitle_file('Test.srt')
I don't have the add_slave() function on my local version of vlc, but I would assume it's safe to say functionality stayed the same for compatibility reasons.
If you are using vlc 2.2, you should use
player.video_set_subtitle_file('Test.srt')
but this method has been deprecated in the 3.0 release and you should use add_slave.
You can have a look at https://en.wikipedia.org/wiki/URL#Syntax it will help you with the URL concept, and https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/ for the application to Windows paths.
I am trying to test a simple example program on Raspberry PI, to start test OpenCV function on Raspberry PI.
After successful compilation, I get an empty window.
The code is an example code when could be found on the OpenCV website, however the only part I change is name of the picture.
IplImage* img = cvLoadImage("pic1.jpg", 3);
All I get in an empty window. The pic.jpg is saved in the home directory(home/pi).
Anyone came across this before?
Regards
Make sure object file and jpg that you're trying to load is in the same directory. (home)
Or just use complete path like this.
IplImage* img = cvLoadImage("/home/pi/pic1.jpg", 3);
Hope it helps.
I'm doing a game with wx.python and when I try to add a background music using wx.Sound I got the following error:
Python error:
Sound file 'images/game.wav' is in unsupported format.
This is the code I use. I've seen this code many times on the web but none had
the same problem:
sound = wx.Sound("images/game.wav")
sound.Play(wx.SOUND_ASYNC)
Sounds like you need to save the WAV file in a different format. WAV files are not all created equal.
http://en.wikipedia.org/wiki/WAV#WAV_file_compression_codecs_compared
Why not use wx.media or maybe the mplayer widget? I have a tutorial on each of these:
http://www.blog.pythonlibrary.org/2010/07/24/wxpython-creating-a-simple-media-player/
http://www.blog.pythonlibrary.org/2010/04/20/wxpython-creating-a-simple-mp3-player/