<commit_before>package stt

import (
	"encoding/binary"
	"io/ioutil"
	"os"
	"os/exec"
	"time"

	"code.google.com/p/portaudio-go/portaudio"
)

// Transcriber transcribes an audio file
type Transcriber interface {
	Transcribe(path string) string
}

// RecordAndTranscribe records audio for Duration and uses the text to speech engine
// defined to format the speech audio into a string.
func RecordAndTranscribe(t Transcriber, duration time.Duration) string {
	timer := time.NewTimer(time.Second * duration)
	f, _ := ioutil.TempFile(os.TempDir(), "pa")
	defer f.Close()
	defer os.Remove(f.Name())
	defer timer.Stop()

	record(f, timer.C)

	exec.Command("afplay", f.Name()).Run()

	return t.Transcribe(f.Name())
}

// Slightly modified exact copy of the portaudio example<commit_msg>google import not maintained anymore<commit_after>package stt

import (
	"encoding/binary"
	"io/ioutil"
	"os"
	"os/exec"
	"time"

	"github.com/gordonklaus/portaudio"
)

// Transcriber transcribes an audio file
type Transcriber interface {
	Transcribe(path string) string
}

// RecordAndTranscribe records audio for Duration and uses the text to speech engine
// defined to format the speech audio into a string.
func RecordAndTranscribe(t Transcriber, duration time.Duration) string {
	timer := time.NewTimer(time.Second * duration)
	f, _ := ioutil.TempFile(os.TempDir(), "pa")
	defer f.Close()
	defer os.Remove(f.Name())
	defer timer.Stop()

	record(f, timer.C)

	exec.Command("afplay", f.Name()).Run()

	return t.Transcribe(f.Name())
}

// Slightly modified exact copy of the portaudio example
{'fraction_non_alphanumeric': 0.12253968253968255, 'fraction_numerical': 0.0, 'mean_word_length': 4.510489510489511, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4339141', 'n_tokens_mistral': 543, 'n_tokens_neox': 522, 'n_words': 149}