maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   N900 as a talking parrot (https://talk.maemo.org/showthread.php?t=91467)

pichlo 2013-09-26 13:00

N900 as a talking parrot
 
[Solution in post #6]

Okay, I admit that this is a crazy idea but...

For a one-off application, I want "something" to continuously monitor an audio line-in (mono would do just fine), detect audio over a certain threshold level, record it until it drops back below the threshold, wait for a given period, play it back, go back to monitoring. And I want it to run unattended.

Detecting the threshold should be easy as the input line is squelched, so the level should be at zero (bar the input electronic's own noise) most of the time.

I did an online search and found at least one parrot program for Windows, but not that flexible (you need to press a button to record, it plays back randomly...). Then I had the brilliant idea to harness my spare N900 to do something like that.

My experience with Linux audio programming equals exactly zero. I suppose I could rip Recaller, myDicto or Orecchiette to shreds and learn something in the process, but I thought I'd ask first. Perhaps what I want could be done with a script? It sounds crazy, but having seen what people can do with a simple command line (like streaming video to a PC), my confidence in what Linux can do for someone who knows how to ask has no limits ;)

juiceme 2013-09-26 14:03

Re: N900 as a talking parrot?
 
Quote:

Originally Posted by pichlo (Post 1376939)
Okay, I admit that this is a crazy idea but...

For a one-off application, I want "something" to continuously monitor an audio line-in (mono would do just fine), detect audio over a certain threshold level, record it until it drops back below the threshold, wait for a given period, play it back, go back to monitoring. And I want it to run unattended.

Detecting the threshold should be easy as the input line is squelched, so the level should be at zero (bar the input electronic's own noise) most of the time.

I did an online search and found at least one parrot program for Windows, but not that flexible (you need to press a button to record, it plays back randomly...). Then I had the brilliant idea to harness my spare N900 to do something like that.

My experience with Linux audio programming equals exactly zero. I suppose I could rip Recaller, myDicto or Orecchiette to shreds and learn something in the process, but I thought I'd ask first. Perhaps what I want could be done with a script? It sounds crazy, but having seen what people can do with a simple command line (like streaming video to a PC), my confidence in what Linux can do for someone who knows how to ask has no limits ;)

Sounds dead easy. If you can detect the start of the event (when something is audible) and the stop of it, a simple script that pulls audio off the device into a temp file, then plays it out is just some ten lines of bash.

pichlo 2013-09-26 14:44

Re: N900 as a talking parrot?
 
OK, so howto?

When I said the detection should be easy I meant the conditions are well defined. It should be easy for someone who knows how to do it but, as I say, I am a complete noob in software audio processing. Linux or otherwise.

I was even thinking about two daemons, one continuously recording audio in, let's say, one-second chunks, the other one picking up those chunks, analyzing them and deleting if found to contain silence. Definitely a battery - and possibly eMMC - killer but I only want to run it for one day and on a charger. (And stream to a disposable SD card.)

BTW, where did the tag come from? ;)

nokiabot 2013-09-26 16:23

Re: N900 as a talking parrot?
 
Crazy idea i want this !

juiceme 2013-09-26 19:02

Re: N900 as a talking parrot?
 
Quote:

Originally Posted by pichlo (Post 1376963)
I was even thinking about two daemons, one continuously recording audio in, let's say, one-second chunks, the other one picking up those chunks, analyzing them and deleting if found to contain silence. Definitely a battery - and possibly eMMC - killer but I only want to run it for one day and on a charger. (And stream to a disposable SD card.)

That dould work, yes, but I guess there should be a simpler way to detect when sound is present.
Unfortunately I do not know that much about N900 so I cannot give exact advice on how to do it.

pichlo 2013-10-02 20:52

Re: N900 as a talking parrot?
 
For those of you still curious, here's my solution. Not exactly as I would ideally like but good enough for my purposes.

An extensive search on this forum yielded this post about recording and playing back audio from the command line. Easy as pie. The next step was to sort out the triggers. I have not yet figured out how to catch the end of the event and would appreciate any input on that. For the time being, I am using a timer which is good enough for my purposes. But how to trigger the start?

It turned out I had the right tool with me all this time: VU Meter! This nifty utility can run a command at a predefined threshold volume. The rest was to write a simple script and configure VU Meter.

The only problem was that VU Meter executed the script every time the threshold was exceeded, even if a previous instance was already running. So I had to take care of that. Oh, and I had to configure tracker to ignore the target directory. The same effect could be achieved by using a different directory but I wanted the target under MyDocs, to make sure I have enough space and to be available in mass storage mode.

Without further ado, here is my magic script:
Code:

#!/bin/bash

# A simple script to record some sound, wait a bit
# and play it back. Like a talking parrot.
# Takes two command-line parameters:
# $1 ... how long to record
# $2 ... how long to wait before playback

# Work out the file name based on current date/time
fpath=/home/user/MyDocs/.sounds/Recordings
fflag=$fpath/Parrot-in-use
fname=$fpath/Parrot-`date +%Y%m%d-%H%M%S`.raw

# Prevent multiple parallel instances
if [ -e "$fflag" ] ; then
    exit 0
fi
touch $fflag

# Display notification banner
banner()
{
  o=org
  f=freedesktop
  n=Notifications
  dbus-send --type=method_call --dest=$o.$f.$n \
    /$o/$f/$n $o.$f.$n.SystemNoteInfoprint \
    string:"Parrot $1..."
}

# Record...
banner "recording"
parec $fname &
sleep $1
killall parec

# ...wait a bit...
banner "waiting"
sleep $2

# ...and play it back
banner "playing"
pacat $fname

rm $fflag


bla1 2014-06-02 11:18

Re: N900 as a talking parrot
 
Out of plain curiosity - what are you using that for? Kids?

I was wondering about variant that would say the thing you've just said in N900's own voide (espeak). But, it would require pocketsphinx to make it understand, and as Saera proved, it's not working ideally.

pichlo 2014-06-02 19:49

Re: N900 as a talking parrot
 
Quote:

Originally Posted by bla1 (Post 1427813)
Out of plain curiosity - what are you using that for?

Thanks for reminding me about this. I originally wanted it to implement a sort-of radio repeater. Hook up a computer - or, in this case an N900 - to a two-way radio. The radio's earphone output to the mic input and vice-versa. Imagine Anna and Elsa want to talk through two-way radios but are just out of range from each other. Put a repeater somewhere in the middle. When Anna talks, Elsa can't hear her, but the repeater can. It will record Anna's message and then play it back, so Elsa can hear (and so can Anna, which may feel a bit strange but may also be a useful feedback about the connection quality).

In fact the connection quality test was my primary reason for wanting this in the first place :) Unfortunately other things got in the way and I could not proceed to the implementation for a while and then I forgot about it altogether. Now you've reminded me, I pretty much have to :)

backcover_press_service 2014-06-02 20:26

Re: N900 as a talking parrot
 
Absolutely awesome and hilarious, in positive way. If I stumble upon talking N900's in some mountain path or forest late at night, I'll know what it is, at last ;)

gianko 2014-06-02 23:57

Re: N900 as a talking parrot
 
i know some people doing it with Python

https://github.com/zioproto/pyparrot

they use a vhf radio with a Cubieboard

there is a video in this italian blog post http://zioproto.ninux.org/wordpress/...-e-cubieboard/


All times are GMT. The time now is 06:51.

vBulletin® Version 3.8.8