Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
alading
Visitor

How to use roMicrophone in Roku development?

Hi,  Greeting

I am very new to Roku development. Currently I am researching to use  remote mic to record the user commands by using roMicrophone;
My code like this:

mic = createObject("roMicrophone")
print mic.CanRecord()
mic.StartRecording()

In debug, canRecord() return true, but the error is given when I call StartRecoridng()
BRIGHTSCRIPT: ERROR: roMicrophone.StartRecording: message port not set: pkg:/components/dialogscene.brs(25)

But in main.brs , I have already add message port such as

screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)

 Does anybody have the clue why it happens?  and please let me know where I am wrong in using this component.

thanks

Alading
0 Kudos
4 REPLIES 4
renojim
Community Streaming Expert

Re: How to use roMicrophone in Roku development?

I haven't used it (didn't even know it existed), but you need to set a message port on the roMicrophone object: mic.SetMessagePort(m.port)

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
alading
Visitor

Re: How to use roMicrophone in Roku development?

HI, JT

Thanks for your kindly help. I add code

  mic = createObject("roMicrophone")
  print mic.CanRecord()
  mic.SetMessagePort(m.port)
  mic.StartRecording()

But it still reports the error 

BRIGHTSCRIPT: ERROR: roMicrophone.StartRecording: message port not set:


Any clue?  thanks

Alading
0 Kudos
renojim
Community Streaming Expert

Re: How to use roMicrophone in Roku development?

I played with this for a little while and had minimal success.  I'm not sure it's worth pursuing.  I was able to use RecordToFile to record short clips, but most times it recorded nothing and when it did record something it was very short (a second or less) and just cut off whenever it wanted to.  I was able to receive events sometimes, but I never looked at the data.

What is the result of your "print mic.CanRecord()"?  Sometimes I would get false and I think I'd have to reboot to get it back to returning true.  Since m has different uses, you might want to create a message port just for your testing:
mic = createObject("roMicrophone")
print mic.CanRecord() ' <- better print true or there's no sense in continuing
port = CreateObject("roMessagePort")
mic.SetMessagePort(port)
mic.StartRecording()


-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
alading
Visitor

Re: How to use roMicrophone in Roku development?

 It works and I received some event when I start recording even sometimes it still works as expected.
Thanks, JT. Let me know if I need to accept the answer or anything to help you promote your level as I am new in the Forum.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.