हैलो, मैं खेलने और एक लिनक्स (अधिमानतः उबंटू) सिस्टम पर रिकॉर्ड ऑडियो के लिए एक रास्ता तलाश रहे हैं। मैं वर्तमान में voice recognition toolkit पर फ्रंट-एंड पर काम कर रहा हूं जो
PocketSphinx
औरJulius
के लिए ध्वनि मॉडल को अनुकूलित करने के लिए आवश्यक कुछ चरणों को स्वचालित करेगा।सी ++ में लिनक्स पर आप ऑडियो (WAV पर) कैसे चलाते हैं या रिकॉर्ड करते हैं?
ऑडियो इनपुट/आउटपुट के वैकल्पिक साधन के सुझाव का स्वागत करते हैं , साथ ही बग नीचे दिखाया गया है करने के लिए एक ठीक कर रहे हैं।
यहाँ वर्तमान कोड मैं अब तक एक .WAV
फ़ाइल खेलने के लिए उपयोग किया है है:
void Engine::sayText (const string OutputText) {
string audioUri = "temp.wav";
string requestUri = this->getRequestUri(OPENMARY_PROCESS , OutputText.c_str());
int error , audioStream;
pa_simple *pulseConnection;
pa_sample_spec simpleSpecs;
simpleSpecs.format = PA_SAMPLE_S16LE;
simpleSpecs.rate = 44100;
simpleSpecs.channels = 2;
eprintf(E_MESSAGE , "Generating audio for '%s' from '%s'..." , OutputText.c_str() , requestUri.c_str());
FILE* audio = this->getHttpFile(requestUri , audioUri);
fclose(audio);
eprintf(E_MESSAGE , "Generated audio.");
if ((audioStream = open(audioUri.c_str() , O_RDONLY)) < 0) {
fprintf(stderr , __FILE__": open() failed: %s\n" , strerror(errno));
goto finish;
}
if (dup2(audioStream , STDIN_FILENO) < 0) {
fprintf(stderr , __FILE__": dup2() failed: %s\n" , strerror(errno));
goto finish;
}
close(audioStream);
pulseConnection = pa_simple_new(NULL , "AudioPush" , PA_STREAM_PLAYBACK , NULL , "openMary C++" , &simpleSpecs , NULL , NULL , &error);
for (int i = 0;;i++) {
const int bufferSize = 1024;
uint8_t audioBuffer[bufferSize];
ssize_t r;
eprintf(E_MESSAGE , "Buffering %d..",i);
/* Read some data ... */
if ((r = read(STDIN_FILENO , audioBuffer , sizeof (audioBuffer))) <= 0) {
if (r == 0) /* EOF */
break;
eprintf(E_ERROR , __FILE__": read() failed: %s\n" , strerror(errno));
if (pulseConnection)
pa_simple_free(pulseConnection);
}
/* ... and play it */
if (pa_simple_write(pulseConnection , audioBuffer , (size_t) r , &error) < 0) {
fprintf(stderr , __FILE__": pa_simple_write() failed: %s\n" , pa_strerror(error));
if (pulseConnection)
pa_simple_free(pulseConnection);
}
usleep(2);
}
/* Make sure that every single sample was played */
if (pa_simple_drain(pulseConnection , &error) < 0) {
fprintf(stderr , __FILE__": pa_simple_drain() failed: %s\n" , pa_strerror(error));
if (pulseConnection)
pa_simple_free(pulseConnection);
}
}
नोट: आप इस फाइल करने के लिए कोड के बाकी चाहते हैं, आप इसे लॉन्चपैड से सीधे here डाउनलोड कर सकते हैं ।
अद्यतन: मैं GStreamermm
उपयोग करने की कोशिश, और यह काम नहीं करेगा:
Glib::RefPtr<Pipeline> pipeline;
Glib::RefPtr<Element> sink, filter, source;
Glib::RefPtr<Gio::File> audioSrc = Gio::File::create_for_path(uri);
pipeline = Pipeline::create("audio-playback");
source = ElementFactory::create_element("alsasrc","source");
filter = ElementFactory::create_element("identity","filter");
sink = ElementFactory::create_element("alsasink","sink");
//sink->get_property("file",audioSrc);
if (!source || !filter || !sink){
showErrorDialog("Houston!","We got a problem.");
return;
}
pipeline->add(source)->add(filter)->add(sink);
source->link(sink);
pipeline->set_state(Gst::STATE_PLAYING);
showInformation("Close this to stop recording");
pipeline->set_state(Gst::STATE_PAUSED);
का उपयोग कर सकते हैं यह [stackoverflow] (http://stackoverflow.com/) के लिए एक बेहतर सवाल होगा। –
मैं खेल और रिकॉर्डिंग के लिए जीस्ट्रीमर लाइब्रेरी पर विचार करता हूं। लेकिन मुझे लगता है कि पल्स में रिकॉर्डिंग विकल्प भी होना चाहिए? – Petriborg
@ माइकल मैंने इसे प्रोग्रामिंग पर पोस्ट किया, क्योंकि मुझे लगता है कि यह प्रोग्रामिंग से संबंधित था। @ पेट्रीबॉर्ग क्या आप ऐसा करने का तरीका प्रदर्शित कर सकते हैं या ** अच्छा ** लिंक कैसे करें? जीस्ट्रीमर केवल ओजीजी का समर्थन करता है और सीएमयूएसफिनक्स को डब्ल्यूएवी फाइलों की आवश्यकता होती है। – jackyalcine