oto icon indicating copy to clipboard operation
oto copied to clipboard

record audio

Open joeblew99 opened this issue 7 years ago • 9 comments

here is a way to record audi for windows using the same dll sycall you use. I also need to record audio on other OS's. Do you think that the same approach can be used for them ?

// Record Windows Audio project main.go
package main

import (
	"fmt"
	"log"
	"syscall"
	"time"
	"unsafe"
)

var (
	winmm         = syscall.MustLoadDLL("winmm.dll")
	mciSendString = winmm.MustFindProc("mciSendStringW")
)

func MCIWorker(lpstrCommand string, lpstrReturnString string, uReturnLength int, hwndCallback int) uintptr {
	i, _, _ := mciSendString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpstrCommand))),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpstrReturnString))),
		uintptr(uReturnLength), uintptr(hwndCallback))
	return i
}

func main() {
	fmt.Println("winmm.dll Record Audio to .wav file")

	i := MCIWorker("open new type waveaudio alias capture", "", 0, 0)
	if i != 0 {
		log.Fatal("Error Code A: ", i)
	}

	i = MCIWorker("record capture", "", 0, 0)
	if i != 0 {
		log.Fatal("Error Code B: ", i)
	}

	fmt.Println("Listening...")

	time.Sleep(10 * time.Second)

	i = MCIWorker("save capture mic.wav", "", 0, 0)
	if i != 0 {
		log.Fatal("Error Code C: ", i)
	}

	i = MCIWorker("close capture", "", 0, 0)
	if i != 0 {
		log.Fatal("Error Code D: ", i)
	}

	fmt.Println("Audio saved to mic.wav")
}

joeblew99 avatar Jun 06 '17 09:06 joeblew99

So you are suggesting a recording feature? My some random thoughts are:

  • Now oto implements Player which is io.Writer, so the newly introduced struct would be something which is io.Reader. That's interesting. Very consistent.
  • However, I don't see my use cases and I can't do dog-fooding. Is there any other people who want this feature? Is this high demand?
  • Besides io.Reader, there should be other configurations but I'm not familiar with this field.

hajimehoshi avatar Jun 06 '17 14:06 hajimehoshi

Hey :)

Here are my use cases:

  1. talk to the game. This then allows you to controll things with your "meat sticks", but also your voice. https://www.reddit.com/r/samharris/comments/5rlqs0/replacing_our_meat_sticks/ NLP on voice is pretty fast now and not hard to do in golang. You can use simpe commands like "change weapon" or "open chat with paul", etc

  2. chat with other players your in the game with...

  3. Chat with Bots your in the game with...

  4. Turing test. joking...

On Tue, Jun 6, 2017 at 4:26 PM Hajime Hoshi [email protected] wrote:

So you are suggesting a recording feature? My some random thoughts are:

  • Now oto implements Player which is io.Writer, so the newly introduced struct would be something which is io.Reader. That's interesting. Very consistent.
  • However, I don't see my use cases and I can't do dog-fooding. Is there any other people who want this feature? Is this high demand?
  • Besides io.Reader, there should be other configurations but I'm not familiar with this field.

— You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub https://github.com/hajimehoshi/oto/issues/8#issuecomment-306502853, or mute the thread https://github.com/notifications/unsubscribe-auth/ALcac7HXcAcLPYZCvt678XK7O_36xxbxks5sBWGHgaJpZM4NxDtu .

joeblew99 avatar Jun 06 '17 15:06 joeblew99

Well, I understood use cases, though I think this task still would be low priority... The actual oto user @faiface might have another idea.

hajimehoshi avatar Jun 06 '17 16:06 hajimehoshi

I'd say this is a functionality which could be supported for completeness and the few use-cases. However, I agree it's low priority, very few games actually use sound recording, playing is much more useful. But eventually, if all other issues are resolved and there's nothing to do, recording wouldn't be a bad idea IMHO.

faiface avatar Jun 06 '17 16:06 faiface

I agree it's less useful. It's at least worth a shot since your going all in on the API restructuring. If it's too hard can always bail on it for later version.

I am using Google cloud for NLP currentky. But bringing up an embedded version that will work on anything locally now. The Carnegie Mellon code is the current gold standard and so wrong a bridge from golang to the cpp code. Will try to loop it into your stuff and integrate.

NLP may seem kind of silly but after working on 3 ML projects for games and being a total non believer in its usefulness I became a convert after seeing the pilot studies in house. VR is also crying out for it because normal interaction systems using " meat sticks" fall apart pretty fast.

joeblew99 avatar Jun 08 '17 17:06 joeblew99

I agree it's less useful. It's at least worth a shot since your going all in on the API restructuring. If it's too hard can always bail on it for later version.

Adding this feature can be done anytime because this is new. Whether we are changing the API or not doesn't matter.

I am using Google cloud for NLP currentky. But bringing up an embedded version that will work on anything locally now. The Carnegie Mellon code is the current gold standard and so wrong a bridge from golang to the cpp code. Will try to loop it into your stuff and integrate. NLP may seem kind of silly but after working on 3 ML projects for games and being a total non believer in its usefulness I became a convert after seeing the pilot studies in house. VR is also crying out for it because normal interaction systems using " meat sticks" fall apart pretty fast.

I understand that voice is useful and faster than other physical way because of human body's restriction, but I couldn't understand the other part... What is NLP? What is ML?

hajimehoshi avatar Jun 08 '17 18:06 hajimehoshi

NLP is how you interpret what a human says of types and route to to actual commands.

ML is machine learning in general. NLP is a beach of MLP

joeblew99 avatar Jun 10 '17 10:06 joeblew99

https://github.com/MarkKremer/microphone exists, although it's aimed at working with the higher-level beep library, which uses oto.

makew0rld avatar Dec 22 '20 04:12 makew0rld

I would be very interested in a pure Go implementation for audio recording. For now it seems the smallest dependency is https://github.com/gen2brain/malgo which is build upon the miniaudio C library. It would be great to be able to record and playback audio with the same package without requiring cgo.

samborkent avatar Jan 18 '24 12:01 samborkent